{"id":16255298,"url":"https://github.com/qubyte/qrcode-png","last_synced_at":"2025-08-05T15:13:59.572Z","repository":{"id":45890724,"uuid":"425617514","full_name":"qubyte/qrcode-png","owner":"qubyte","description":"Create QR code PNG files! This module has a custom built PNG encoder for QR codes to make them tinier than the competition, and works *fast* in both the browser and Node. It has a light dependency tree.","archived":false,"fork":false,"pushed_at":"2023-10-21T11:08:17.000Z","size":110,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T08:43:19.487Z","etag":null,"topics":["javascript","png","qr-code","qrcode"],"latest_commit_sha":null,"homepage":"","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/qubyte.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,"governance":null}},"created_at":"2021-11-07T21:14:43.000Z","updated_at":"2022-05-01T09:39:38.000Z","dependencies_parsed_at":"2022-09-05T18:21:33.653Z","dependency_job_id":"a6bc6a25-a455-41c2-9fa8-4a216e501286","html_url":"https://github.com/qubyte/qrcode-png","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubyte%2Fqrcode-png","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubyte%2Fqrcode-png/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubyte%2Fqrcode-png/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qubyte%2Fqrcode-png/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qubyte","download_url":"https://codeload.github.com/qubyte/qrcode-png/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247847614,"owners_count":21006100,"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":["javascript","png","qr-code","qrcode"],"created_at":"2024-10-10T15:29:21.692Z","updated_at":"2025-04-08T13:18:53.323Z","avatar_url":"https://github.com/qubyte.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qrcode-png\n\nMake a QR code PNG from a string. This module uses the [qrcode-svg] module\ninternally, and inherits some of its options. PNGs created by this library are\nmore efficiently encoded than\n[those created by the most popular alternative](#benchmarks) thanks to a PNG\nencoder designed for the specific use case of QR codes.\n\n## Install\n\n```shell\nnpm i qrcode-png\n```\n\n## Usage\n\n```javascript\nconst qrcode = require('qrcode-png');\n\nconst pngTypedArray = qrcode(content, options);\n```\n\nThe return value of `qrcode` is an instance of [`Uint8Array`][Uint8Array]. If\nyou're using it in Node.js, many core libraries will accept it as a substitute\nfor a buffer. Any time you need a buffer you can wrap the `Uint8Array` in one\nwithout copying:\n\n```javascript\nconst pngBuffer = Buffer.from(qrcode(content, options).buffer);\n```\n\n## `content`\n\n`content` is the string you want encoded in the QR code. It must be a string\nwith length greater than 0.\n\n## `options`\n\n`options` is an optional object with these fields:\n\n* **padding** - Background colored padding around the QR code, `4` modules by default, `0` for no border.\n* **color** - color of modules (squares), a length 3 (or 4 if you want to include alpha) array RGB values in the range 0-255, e.g. `[0, 0, 0]` for black. The default is black.\n* **background** - color of background, a length 3 (or 4 if you want to include alpha) array RGB values in the range 0-255, e.g. `[255, 255, 255]` for white. The default is white.\n* **ecl** - error correction level: `L`, `M`, `H`, `Q`. Default `M`.\n* **deflate** - a deflate implementation such as Node's `zlib.deflateSync` or `pako.deflate`. Curry it with options you want it to use. By default a function is used which creates a valid PNG, but does not compress data. You may find it sufficient.\n\n## Writing to a file\n\nThis library returns a TypedArray, which you can pass directly to an `fs`\nmethod.\n\n```javascript\nconst fs = require('fs');\nconst qrcode = require('qrcode-png');\n\nconst pngTypedArray = qrcode(content);\n\nfs.writeFileSync('./my-qr-code.png', pngTypedArray);\n```\n\n## Customizing the deflate implementation\n\nIt's possible (and enouraged in Node) to pass in a custom deflate function. For\nthe browser, [pako] has a similar `deflate` function.\n\n```javascript\nconst fs = require('fs');\nconst zlib = require('zlib');\nconst qrcode = require('qrcode-png');\n\nfunction deflate(buffer) {\n  return zlib.deflateSync(buffer, { level: zlib.constants.Z_BEST_COMPRESSION });\n}\n\nconst pngTypedArray = qrcode(content, { deflate });\n```\n\n## Use in the browser\n\nA bundler such as webpack or rollup with CommonJS and node module resolution\nmust be used to bundle the [qrcode-svg] module this package depends on. [pako]\nis recommended for better `deflate` compression.\n\n## About the images produced\n\nThis library produces PNGs with a pixel per module (square). To be useful the\nwidth and height should be set, and some styles applied to avoid it looking\nblurry.\n\n```html\n\u003cimg class=\"qr\" src\"./my-qr-code.png\" width=\"100\" height=\"100\"\u003e\n```\n\n```css\nimg.qr {\n  text-align: center;\n  image-rendering: auto;\n  image-rendering: crisp-edges;\n  image-rendering: optimize-contrast;\n  image-rendering: optimizeSpeed;\n  image-rendering: -webkit-optimize-contrast;\n  image-rendering: pixelated;\n}\n```\n\nIf you want to inline the png in your HTML a convenience method is provided:\n\n```javascript\nconst dataUrl = qrcode(\"Hello, world!\").toDataUrl();\n```\n\n## Benchmarks\n\nIn informal benchmarks against [`qrcode`][qrcode] (which provides similar\nfunctionality for PNG data URLS), this library generates URLs in about half the\ntime and the results are about 25% of the size (a considerable saving) for the\nsame error correction level. **No claim is made of a fair test!** If your use\ncase is performance sensitive you should do your own analysis for your use case.\n\nSome speculation: The savings seen from this library are likely due to a\ncombination of factors, but a large part is that this library uses color-type 0\n(for the default black and white) or 3 for PNG encoding, in both cases with a\nbit depth of 1 (a very compact representation). [`qrcode`][qrcode] uses\n[`pngjs`][pngjs], which does not support writing color-type 3 PNGs.\n[`qrcode`][qrcode] produces color-type 6 PNGs (truecolor with alpha), with a bit\ndepth of 8. Filters (which [`pngjs`][pngjs] has advanced behaviour for but which\nthis library does not) may recover some of the space wasted by the higher bit\ndepth.\n\n[Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array\n[qrcode-svg]: https://npmjs.com/package/qrcode-svg\n[pako]: https://npmjs.com/package/pako\n[better to use a buffer]: https://nodejs.org/dist/latest-v16.x/docs/api/globals.html#atobdata\n[qrcode]: https://npmjs.com/package/qrcode\n[pngjs]: https://npmjs.com/package/pngjs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubyte%2Fqrcode-png","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqubyte%2Fqrcode-png","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqubyte%2Fqrcode-png/lists"}