[string-pixel-width](https://github.com/adambisek/string-pixel-width)
===================================
[![Build Status](https://travis-ci.org/adambisek/string-pixel-width.svg?branch=master)](https://travis-ci.org/adambisek/string-pixel-width)
[![npm version](https://img.shields.io/npm/v/string-pixel-width.svg?style=flat-square)](https://www.npmjs.com/package/string-pixel-width)
[![Coverage Status](https://coveralls.io/repos/github/adambisek/string-pixel-width/badge.svg?branch=master)](https://coveralls.io/github/adambisek/string-pixel-width?branch=master)
String pixel width measurement on the backend in Javascript.
[Why I created this package? Read more about purpose](https://medium.com/@adambisek/text-pixel-width-measuring-on-javascript-backend-node-js-2b82bea97fab#.8ypyiffyw)
Installation
------------
To install the stable version:
<code>
npm install --save string-pixel-width
</code>
Supported fonts:
------------
- Andale Mono
- Arial
- Avenir
- Avenir Next
- Comic Sans MS
- Courier New
- Georgia
- Helvetica
- Impact
- 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.
1. Clone the repository
2. Open file ```src/pixelWidthCalculator.html``` in your editor
3. Add your font name into array of fonts (currently var websafe) and save
4. Open up ```src/pixelWidthCalculator.html``` in Google Chrome. It should look like this:
![PHPStan](docs/string-pixel-width-1.png)
5. 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.**
没有合适的资源?快使用搜索试试~ 我知道了~
使用 Javascript (Node.Js) 在服务器上以像素为单位 快速测量字符串宽度_代码_相关文件_下载
共15个文件
js:4个
eslintrc:2个
babelrc:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 192 浏览量
2022-07-11
23:54:03
上传
评论
收藏 178KB ZIP 举报
温馨提示
Javascript 后端的字符串像素宽度测量。 支持的字体: Andale Mono Arial Avenir Avenir Next Comic Sans MS Courier New Georgia Helvetica Impact Times New Roman Trebuchet MS Verdana Webdings Open Sans Tahoma 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
string-pixel-width-master.zip (15个子文件)
string-pixel-width-master
.travis.yml 90B
.eslintrc 141B
.babelrc 84B
docs
string-pixel-width-1.png 162KB
package.json 1KB
__tests__
.eslintrc 36B
index.js 1KB
src
index.js 987B
widthsMap.js 85KB
pixelWidthCalculator.html 2KB
.npmignore 70B
.gitignore 44B
gulpfile.babel.js 684B
README.md 3KB
yarn.lock 166KB
共 15 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功