npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

optical-properties

v1.0.0

Published

Calculate optical properties of a character, imageData or canvas

Downloads

217,167

Readme

optical-properties unstable

Get optical params of a character, canvas or image data. Useful to do kerning, normalize size or adjust vertical/horizontal alignment.

optical-properties

See demo.

Usage

npm install optical-properties

const optics = require('optical-properties')

let w = canvas.width, h = canvas.height, ctx = canvas.getContext('2d')

//get optical params
let {bounds, center, radius} = optics('▲', {size: h, fontSize: h/2})

//make sure radius of char is at least half of canvas height
let scale = h*.5 / (radius*2)

//optical center shift from the real center
let diff = [w*.5 - center[0], h*.5 - center[1]]

//draw normalized character
ctx.font = size*cale + 'px sans-serif'
ctx.fillText('▲', w*.5 + diff[0]*scale, h*.5 + diff[1]*scale)

API

let props = optics(char|canvas|imageData, options?)

Measures optical properties of a character, canvas or imageData based on options. Canvas is expected to be rectangular.

Options:

  • size − size of canvas to use, bigger is slower but more precise and vice-versa. Defaults to 200.
  • fontFamily − font family to use for the character, defaults to sans-serif.
  • fontSize − size of glyph, defaults to 100.

Returns object with properties:

  • center − coordinates of optical center as [cx, cy].
  • bounds − character bounding box [left, top, right, bottom].
  • radius − distance from the optical center to the outmost point.

Credits

© 2017 Dima Yv. MIT License