1.11.0 • Published 1 year ago
string-pixel-width v1.11.0
string-pixel-width
String pixel width measurement on the backend in Javascript.
Why I created this package? Read more about purpose
Installation
To install the stable version:
Supported fonts:
- Andale Mono
- Arial
- Avenir
- Avenir Next
- Comic Sans MS
- Courier New
- Georgia
- Helvetica
- Impact
- Inter
- Times New Roman
- Trebuchet MS
- Verdana
- Webdings
- Open Sans
- Tahoma
Example
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { size: 10 });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 43.5px long in the size of 10px.
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { font: 'impact', size: 10 });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 42px long in the size of 10px.
var pixelWidth = require('string-pixel-width');
const width = pixelWidth('My text ...', { font: 'open sans', size: 10, bold: true, italic: true });
console.log('This text is ' + width + 'px long in the size of 10px.');
// This text is 47px long in the size of 10px using bold and italic proportions.
How to contribute
PRs are welcome :) This library uses static map of width of every ASCII letter for all supported fonts.
- Clone the repository
- Open file
src/pixelWidthCalculator.html
in your editor - Add your font name into array of fonts (currently var websafe) and save
- Open up
src/pixelWidthCalculator.html
in Google Chrome. It should look like this: - Map of withs will be generated for you - copy it and replace content of file
src/widthsMap.js
Please everytime make sure you don't broke existing fonts - remove any font or broke his widths.
1.11.0
1 year ago
1.10.0
5 years ago
1.9.0
5 years ago
1.8.0
6 years ago
1.7.0
6 years ago
1.6.0
6 years ago
1.5.0
6 years ago
1.4.0
6 years ago
1.3.0
7 years ago
1.2.0
7 years ago
1.1.1
7 years ago
1.1.0
7 years ago
1.0.7
7 years ago
1.0.6
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago