{"id":26949648,"url":"https://github.com/catdad-experiments/libheif-js","last_synced_at":"2025-04-09T23:13:49.816Z","repository":{"id":50052442,"uuid":"234459975","full_name":"catdad-experiments/libheif-js","owner":"catdad-experiments","description":"🤳 libheif as an npm module","archived":false,"fork":false,"pushed_at":"2024-10-14T05:28:37.000Z","size":58,"stargazers_count":75,"open_issues_count":7,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T23:13:46.389Z","etag":null,"topics":["emscripten","heic","heif","libheif","npm-module"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/catdad-experiments.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":"2020-01-17T03:08:40.000Z","updated_at":"2025-04-01T15:49:47.000Z","dependencies_parsed_at":"2023-01-23T08:30:42.328Z","dependency_job_id":"1101e6d7-10d3-472f-8139-0613a51929a5","html_url":"https://github.com/catdad-experiments/libheif-js","commit_stats":{"total_commits":102,"total_committers":2,"mean_commits":51.0,"dds":"0.019607843137254943","last_synced_commit":"841cf2ac5ae0fc4c52aad9571e8a73de65896c8a"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad-experiments%2Flibheif-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad-experiments%2Flibheif-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad-experiments%2Flibheif-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/catdad-experiments%2Flibheif-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/catdad-experiments","download_url":"https://codeload.github.com/catdad-experiments/libheif-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125589,"owners_count":21051770,"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":["emscripten","heic","heif","libheif","npm-module"],"created_at":"2025-04-02T22:16:52.690Z","updated_at":"2025-04-09T23:13:49.795Z","avatar_url":"https://github.com/catdad-experiments.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libheif-js\n\n\u003e An Emscripten build of [`libheif`](https://github.com/strukturag/libheif) distributed as an npm module for Node.JS and the browser.\n\n[![github actions test][github-actions-test.svg]][github-actions-test.link]\n[![jsdelivr][jsdelivr.svg]][jsdelivr.link]\n[![npm-downloads][npm-downloads.svg]][npm.link]\n[![npm-version][npm-version.svg]][npm.link]\n\n[github-actions-test.link]: https://github.com/catdad-experiments/libheif-js/actions?query=workflow%3ACI\n[github-actions-test.svg]: https://github.com/catdad-experiments/libheif-js/actions/workflows/ci.yml/badge.svg\n[npm-downloads.svg]: https://img.shields.io/npm/dm/libheif-js.svg\n[npm.link]: https://www.npmjs.com/package/libheif-js\n[npm-version.svg]: https://img.shields.io/npm/v/libheif-js.svg\n[jsdelivr.svg]: https://img.shields.io/jsdelivr/npm/hm/libheif-js?color=bd33a4\n[jsdelivr.link]: https://www.jsdelivr.com/package/npm/libheif-js\n\nThis module will respect the major and minor versions of the included `libheif`, with the patch version representing changes in this module itself. For the exact version of `libheif`, please see the [install script](scripts/install.js).\n\n## Install\n\n```bash\nnpm install libheif-js\n```\n\n## Usage\n\nStarting with version 1.17, there are multiple variants of `libheif` that you can use:\n\n* The default is still the classic pure-javascript implementation (for backwards compatibility, of course). You can still bundle this into your project with your bundler of choice.\n  ```js\n  const libheif = require('libheif-js');\n  ```\n* There is a `wasm` version available for use in NodeJS. This version will dymanically load the `.wasm` binary at runtime. While you may try to run this through a bundler, you are on your own for making it work.\n  ```js\n  const libheif = require('libheif-js/wasm');\n  ```\n* There is also a `wasm` version that is pre-bundled for you, which includes the `.wasm` binary inside the `.js` bundle. You will have a much easier time using this in your browser bundle project.\n  ```js\n  const libheif = require('libheif-js/wasm-bundle');\n  ```\n\nIf you'd like to include this module directly into an `html` page using a `\u003cscript\u003e` tag, you have the following options:\n\n_Note: in the examples below, make sure to set the latest version when you use it. Always make sure to set a version, to make sure your website does not break unexpectedly when an update is released._\n\n* Use the pure-javascript implementation, exposing a `libheif` global:\n  ```html\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/libheif-js@1.17.1/libheif/libheif.js\"\u003e\u003c/script\u003e\n  ```\n* Use the wasm bundle, exposing a `libheif` global:\n  ```html\n  \u003cscript src=\"https://cdn.jsdelivr.net/npm/libheif-js@1.17.1/libheif-wasm/libheif-bundle.js\"\u003e\u003c/script\u003e\n  ```\n* Use the ES Module version, which now works in all major browsers and you should try it:\n  ```html\n  \u003cscript type=\"module\"\u003e\n    import libheif from 'https://cdn.jsdelivr.net/npm/libheif-js@1.17.1/libheif-wasm/libheif-bundle.mjs';\n  \u003c/script\u003e\n  ```\n\nIn all cases, you can use this sample code to decode an image:\n\n```js\nconst file = fs.readFileSync('./temp/0002.heic');\n\nconst decoder = new libheif.HeifDecoder();\nconst data = decoder.decode(file);\n// data in an array holding all images inside the heic file\n\nconst image = data[0];\nconst width = image.get_width();\nconst height = image.get_height();\n```\n\nIn NodeJS, you might use this decoded data with other libraries, such as `pngjs`:\n\n```js\nconst { PNG } = require('pngjs');\n\nconst imageData = await new Promise((resolve, reject) =\u003e {\n  image.display({ data: new Uint8ClampedArray(width*height*4), width, height }, (displayData) =\u003e {\n    if (!displayData) {\n      return reject(new Error('HEIF processing error'));\n    }\n\n    resolve(displayData);\n  });\n});\n\nconst png = new PNG({ width: imageData.width, height: imageData.height });\npng.data = imageData.data;\n\nconst pngBuffer = PNG.sync.write(png);\n```\n\nIn the browser, you might use this decoded data with `canvas` to display or convert the image:\n\n```js\nconst canvas = document.createElement('canvas');\n\ncanvas.width = width;\ncanvas.height = height;\n\nconst context = canvas.getContext('2d');\nconst imageData = context.createImageData(width, height);\n\nawait new Promise((resolve, reject) =\u003e {\n  image.display(imageData, (displayData) =\u003e {\n    if (!displayData) {\n      return reject(new Error('HEIF processing error'));\n    }\n\n    resolve();\n  });\n});\n\ncontext.putImageData(imageData, 0, 0);\n```\n\n## Related\n\nThis module contains the low-level `libheif` implementation. For more user-friendly functionality, check out these projects:\n\n* [heic-cli](https://github.com/catdad-experiments/heic-cli) - convert heic/heif images to jpeg or png from the command line\n* [heic-convert](https://github.com/catdad-experiments/heic-convert) - convert heic/heif images to jpeg and png\n* [heic-decode](https://github.com/catdad-experiments/heic-decode) - decode heic images to raw image data\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatdad-experiments%2Flibheif-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcatdad-experiments%2Flibheif-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcatdad-experiments%2Flibheif-js/lists"}