unicode-pixel-width

Calculate string pixel width for support to all Unicode characters

Usage no npm install needed!

<script type="module">
  import unicodePixelWidth from 'https://cdn.skypack.dev/unicode-pixel-width';
</script>

README

unicode-pixel-width

String pixel width measurement supporting all Unicode characters

Supported fonts:

  • Arial

Usage

const pixelWidth = require('unicode-pixel-width');

pixelWidth('My text ...', { font: 'Arial', size: 13 }); // 56.55px
pixelWidth('0123456789', { font: 'Arial', size: 13 }); // 72.8px
pixelWidth('ؤإئبةتثجحخدذرزسشصضطظغؼؽؾؿـفقكلمنهوىي', { font: 'Arial', size: 13 }); // 269.62px
pixelWidth('😀😁😂😃😄😅😆😇😈', { font: 'Arial', size: 13 }); // 144px