{"id":16125718,"url":"https://github.com/dy/bitmap-sdf","last_synced_at":"2025-09-12T20:32:17.800Z","repository":{"id":22867505,"uuid":"97527590","full_name":"dy/bitmap-sdf","owner":"dy","description":"Calculate SDF for image/bitmap/bw data","archived":false,"fork":false,"pushed_at":"2023-07-19T14:32:15.000Z","size":67,"stargazers_count":53,"open_issues_count":4,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-29T21:47:09.317Z","etag":null,"topics":["bitmap","sdf"],"latest_commit_sha":null,"homepage":"https://dy.github.io/bitmap-sdf/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","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":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-17T22:24:01.000Z","updated_at":"2025-07-21T08:39:12.000Z","dependencies_parsed_at":"2024-06-18T13:55:06.987Z","dependency_job_id":"59648ad7-aca4-4791-896c-f1b274f7b64d","html_url":"https://github.com/dy/bitmap-sdf","commit_stats":{"total_commits":28,"total_committers":2,"mean_commits":14.0,"dds":0.0714285714285714,"last_synced_commit":"78de3569d32404a7009f62bea3befca55838118a"},"previous_names":["dfcreative/bitmap-sdf"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dy/bitmap-sdf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fbitmap-sdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fbitmap-sdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fbitmap-sdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fbitmap-sdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/bitmap-sdf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fbitmap-sdf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274873290,"owners_count":25365823,"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","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bitmap","sdf"],"created_at":"2024-10-09T21:31:00.459Z","updated_at":"2025-09-12T20:32:17.513Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","readme":"# bitmap-sdf [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges)\n\nCalculate signed distance field for an image / bw-data. Fork of [tiny-sdf](https://github.com/mapbox/tiny-sdf) with reduced API.\n\n![bitmap-sdf](preview.png)\n\n[Demo](https://dy.github.io/bitmap-sdf/)\n\n## Usage\n\n[![npm install bitmap-sdf](https://nodei.co/npm/bitmap-sdf.png?mini=true)](https://npmjs.org/package/bitmap-sdf/)\n\n```js\nconst calcSdf = require('bitmap-sdf')\n\n//draw image\nconst canvas = document.body.appendChild(document.createElement('canvas'))\nconst w = canvas.width = 200, h = canvas.height = 200\nconst ctx = canvas.getContext('2d')\nctx.fillStyle = 'white'\nctx.font = 'bold 30px sans-serif'\nctx.fillText('X', 20, 20)\n\n//calculate distances\nconst distArr = calcSdf(canvas)\n\n//show distances\nconst imgArr = new Uint8ClampedArray(w*h*4)\nfor (let i = 0; i \u003c w; i++) {\n\tfor (let j = 0; j \u003c h; j++) {\n\t\timgArr[j*w*4 + i*4 + 0] = distArr[j*w+i]*255\n\t\timgArr[j*w*4 + i*4 + 1] = distArr[j*w+i]*255\n\t\timgArr[j*w*4 + i*4 + 2] = distArr[j*w+i]*255\n\t\timgArr[j*w*4 + i*4 + 3] = 255\n\t}\n}\nconst data = new ImageData(imgArr, w, h)\nctx.putImageData(data, 0, 0)\n```\n\n### dist = calcSdf(source, options?)\n\nCalculate distance field for the input `source` data, based on `options`. Returns 1-channel array with distance values from `0..1` range.\n\n#### Source:\n\nType | Meaning\n---|---\n_Canvas_, _Context2D_ | Calculates sdf for the full canvas image data based on `options.channel`, by default `0`, ie. red channel.\n_ImageData_ | Calculates sdf for the image data based on `options.channel`\n_Uint8ClampedArray_, _Uint8Array_ | Handles raw pixel data, requires `options.width` and `options.height`. Stride is detected from `width` and `height`.\n_Float32Array_, _Array_ | Handles raw numbers from `0..1` range, requires `options.width` and `options.height`. Stride is detected from `width` and `height`.\n\n#### Options:\n\nProperty | Default | Meaning\n---|---|---\n`cutoff` | `0.25` | Cutoff parameter, balance between SDF inside `1` and outside `0` of glyph\n`radius` | `10` | Max length of SDF, ie. the size of SDF around the `cutoff`\n`width` | `canvas.width` | Width of input data, if array\n`height` | `canvas.height` | Height of input data, if array\n`channel` | `0` | Channel number, `0` is red, `1` is green, `2` is blue, `3` is alpha.\n`stride` | `null` | Explicitly indicate number of channels per pixel. Not needed if `height` and `width` are provided.\n\n## See also\n\n* [font-atlas-sdf](https://github.com/hughsk/font-atlas-sdf) − generate sdf atlas for a font.\n* [tiny-sdf](https://github.com/mapbox/tiny-sdf) − fast glyph signed distance field generation.\n* [optical-properties](https://github.com/dfcreative/optical-properties) − glyph optical center and bounding box calculation\n\n## Alternatives\n\n* [disttransform.wat](https://github.com/LingDong-/wasm-fun/blob/master/wat/disttransform.wat)\n\n## License\n\n(c) 2017 Dima Yv. MIT License\n\nDevelopment supported by plot.ly.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fbitmap-sdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fbitmap-sdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fbitmap-sdf/lists"}