{"id":16125721,"url":"https://github.com/dy/optical-properties","last_synced_at":"2025-09-12T21:33:14.078Z","repository":{"id":57315788,"uuid":"93805772","full_name":"dy/optical-properties","owner":"dy","description":"Get character optical properties","archived":false,"fork":false,"pushed_at":"2019-11-15T04:13:07.000Z","size":40,"stargazers_count":18,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T00:12:21.436Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dfcreative.github.io/optical-properties","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-09T01:18:53.000Z","updated_at":"2023-08-31T14:17:43.000Z","dependencies_parsed_at":"2022-09-05T18:00:26.963Z","dependency_job_id":null,"html_url":"https://github.com/dy/optical-properties","commit_stats":null,"previous_names":["dfcreative/optical-properties"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Foptical-properties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Foptical-properties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Foptical-properties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Foptical-properties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/optical-properties/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232792146,"owners_count":18577261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T21:31:06.249Z","updated_at":"2025-01-06T21:53:43.566Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# optical-properties [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges)\n\nGet optical params of a character, canvas or image data. Useful to do kerning, normalize size or adjust vertical/horizontal alignment.\n\n![optical-properties](https://github.com/dfcreative/optical-properties/blob/gh-pages/index.png?raw=true)\n\nSee [demo](https://dy.github.io/optical-properties).\n\n## Usage\n\n[![npm install optical-properties](https://nodei.co/npm/optical-properties.png?mini=true)](https://npmjs.org/package/optical-properties/)\n\n```js\nconst optics = require('optical-properties')\n\nlet w = canvas.width, h = canvas.height, ctx = canvas.getContext('2d')\n\n//get optical params\nlet {bounds, center, radius} = optics('▲', {size: h, fontSize: h/2})\n\n//make sure radius of char is at least half of canvas height\nlet scale = h*.5 / (radius*2)\n\n//optical center shift from the real center\nlet diff = [w*.5 - center[0], h*.5 - center[1]]\n\n//draw normalized character\nctx.font = size*cale + 'px sans-serif'\nctx.fillText('▲', w*.5 + diff[0]*scale, h*.5 + diff[1]*scale)\n\n```\n\n## API\n\n### let props = optics(char|canvas|imageData, options?)\n\nMeasures optical properties of a character, canvas or imageData based on options. Canvas is expected to be rectangular.\n\nOptions:\n\n* `size` − size of canvas to use, bigger is slower but more precise and vice-versa. Defaults to `200`.\n* `fontFamily` − font family to use for the character, defaults to `sans-serif`.\n* `fontSize` − size of glyph, defaults to `100`.\n\nReturns object with properties:\n\n* `center` − coordinates of optical center as `[cx, cy]`.\n* `bounds` − character bounding box `[left, top, right, bottom]`.\n* `radius` − distance from the optical center to the outmost point.\n\n\n## Credits\n\n© 2017 Dima Yv. MIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Foptical-properties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Foptical-properties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Foptical-properties/lists"}