{"id":31744791,"url":"https://github.com/stacksjs/pngx","last_synced_at":"2025-10-09T12:18:32.823Z","repository":{"id":277076181,"uuid":"931255896","full_name":"stacksjs/pngx","owner":"stacksjs","description":"🏞️ Modern PNG decoding \u0026 encoding.","archived":false,"fork":false,"pushed_at":"2025-10-07T18:03:43.000Z","size":16071,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-07T19:34:12.352Z","etag":null,"topics":["decoder","encoder","library","png","typescript"],"latest_commit_sha":null,"homepage":"https://pngx.netlify.app","language":"TypeScript","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/stacksjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["stacksjs","chrisbbreuer"],"open_collective":"stacksjs"}},"created_at":"2025-02-12T01:06:42.000Z","updated_at":"2025-09-30T07:40:07.000Z","dependencies_parsed_at":"2025-02-12T08:49:29.177Z","dependency_job_id":"d0097200-d63f-4af1-a7be-45c051211abf","html_url":"https://github.com/stacksjs/pngx","commit_stats":null,"previous_names":["stacksjs/ts-png","stacksjs/pngx"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/stacksjs/pngx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fpngx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fpngx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fpngx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fpngx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stacksjs","download_url":"https://codeload.github.com/stacksjs/pngx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stacksjs%2Fpngx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001446,"owners_count":26083078,"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-10-09T02:00:07.460Z","response_time":59,"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":["decoder","encoder","library","png","typescript"],"created_at":"2025-10-09T12:18:27.189Z","updated_at":"2025-10-09T12:18:32.816Z","avatar_url":"https://github.com/stacksjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/stacksjs","https://github.com/sponsors/chrisbbreuer","https://opencollective.com/stacksjs"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\".github/art/cover.jpg\" alt=\"Social Card of this repo\"\u003e\u003c/p\u003e\n\n[![npm version][npm-version-src]][npm-version-href]\n[![GitHub Actions][github-actions-src]][github-actions-href]\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n\u003c!-- [![npm downloads][npm-downloads-src]][npm-downloads-href] --\u003e\n\u003c!-- [![Codecov][codecov-src]][codecov-href] --\u003e\n\n# pngx\n\n\u003e A TypeScript library for encoding \u0026 decoding PNG images with comprehensive type safety and memory management.\n\n## Features\n\n- 📸 **Complete PNG Support**: Full implementation of PNG encoding and decoding\n- 🎨 **Color Types**: Support for Grayscale, RGB, RGBA, and Palette color modes\n- 🔍 **Chunk Processing**: Proper handling of all critical PNG chunks _(IHDR, IDAT, PLTE, IEND)_\n- 💾 **Memory Safe**: Built-in memory management for large images\n- 🎯 **Filtering**: Support for all PNG filter types _(None, Sub, Up, Average, Paeth)_\n- 💪 **Type Safe**: Written in TypeScript with comprehensive type definitions\n- ⚡ **Efficient**: Optimized filtering and compression algorithms\n- 🛡️ **Error Handling**: Robust error handling for malformed PNG data\n- 📦 **Lightweight**: Zero dependencies\n\u003c!-- - 🌐 **Universal**: Works in both Node.js and browser environments --\u003e\n\n## Installation\n\n```bash\nnpm install pngx\n# or\npnpm add pngx\n# or\nbun i pngx\n```\n\n## Usage\n\n### Reading PNG Images\n\n```ts\nimport { PNG } from 'pngx'\n\n// Basic reading\nconst png = new PNG()\nconst buffer = await fs.readFile('image.png')\npng.parse(buffer, (error, data) =\u003e {\n  if (error)\n    throw error\n  console.log(`Dimensions: ${data.width}x${data.height}`)\n})\n\n// Advanced reading with options\nconst png = new PNG({\n  filterType: 4, // Paeth filtering\n  bitDepth: 8, // 8-bit depth\n  colorType: 6 // RGBA color mode\n})\n\n// Access image data\npng.on('parsed', function () {\n  const { width, height, data, gamma } = this\n  // data is a Buffer containing RGBA pixel data\n})\n```\n\n### Writing PNG Images\n\n```ts\nimport { PNG } from 'pngx'\n\n// Create a new PNG with dimensions\nconst png = new PNG({\n  width: 800,\n  height: 600,\n  colorType: 6, // RGBA\n  bitDepth: 8\n})\n\n// Fill with pixel data\nfor (let y = 0; y \u003c png.height; y++) {\n  for (let x = 0; x \u003c png.width; x++) {\n    const idx = (png.width * y + x) \u003c\u003c 2\n    png.data[idx] = 255 // R\n    png.data[idx + 1] = 0 // G\n    png.data[idx + 2] = 0 // B\n    png.data[idx + 3] = 255 // A\n  }\n}\n\n// Write to file\npng.pack().pipe(fs.createWriteStream('output.png'))\n```\n\n### Color Types Support\n\n```ts\nimport { PNG } from 'pngx'\n\n// Grayscale\nconst grayPNG = new PNG({\n  colorType: 0, // Grayscale\n  bitDepth: 8\n})\n\n// RGB\nconst rgbPNG = new PNG({\n  colorType: 2, // RGB\n  bitDepth: 8\n})\n\n// RGBA\nconst rgbaPNG = new PNG({\n  colorType: 6, // RGBA\n  bitDepth: 8\n})\n\n// Palette-based\nconst palettePNG = new PNG({\n  colorType: 3, // Palette\n  bitDepth: 8\n})\n```\n\n### Filter Types\n\nThe library supports all standard PNG filter types:\n\n```ts\nimport { PNG } from 'pngx'\n\n// Specific filter type\nconst png = new PNG({\n  filterType: 0 // None\n  // filterType: 1  // Sub\n  // filterType: 2  // Up\n  // filterType: 3  // Average\n  // filterType: 4  // Paeth\n})\n\n// Adaptive filtering (choose best filter per line)\nconst png = new PNG({\n  filterType: -1 // Adaptive\n})\n```\n\n### Error Handling\n\nThe library provides detailed error messages for common issues:\n\n```ts\ntry {\n  const png = new PNG()\n  png.parse(corruptedBuffer, (error, data) =\u003e {\n    if (error) {\n      if (error.message.includes('signature')) {\n        console.error('Invalid PNG signature')\n      }\n      else if (error.message.includes('IHDR')) {\n        console.error('Invalid header chunk')\n      }\n      else {\n        console.error('PNG parsing error:', error)\n      }\n    }\n  })\n}\ncatch (err) {\n  console.error('Processing error:', err)\n}\n```\n\n## TypeScript Support\n\nFull TypeScript support with detailed type definitions:\n\n```ts\nimport { Buffer } from 'node:buffer'\n\ninterface PNGOptions {\n  width?: number\n  height?: number\n  bitDepth?: 8 | 16\n  colorType?: 0 | 2 | 3 | 4 | 6\n  filterType?: -1 | 0 | 1 | 2 | 3 | 4\n  inputHasAlpha?: boolean\n  deflateLevel?: number\n  deflateStrategy?: number\n}\n\ninterface BitmapData {\n  width: number\n  height: number\n  data: Buffer\n  gamma?: number\n}\n\n// Types are automatically inferred\nconst png = new PNG()\npng.on('parsed', function (this: PNG) {\n  const { width, height, data } = this\n})\n```\n\n## Memory Management\n\nThe library includes built-in memory management for handling large images:\n\n```ts\nimport { PNG } from 'pngx'\n\n// Create PNG with memory constraints\nconst png = new PNG({\n  deflateChunkSize: 32 * 1024, // 32KB chunks\n  deflateLevel: 9, // Max compression\n  filterType: 4 // Paeth filtering\n})\n\n// Handle potential memory errors\npng.on('error', (error) =\u003e {\n  if (error.message.includes('memory')) {\n    console.error('Memory allocation failed:', error)\n  }\n})\n```\n\n## Testing\n\n```bash\nbun test\n```\n\n## Changelog\n\nPlease see our [releases](https://github.com/stackjs/pngx/releases) page for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Community\n\nFor help, discussion about best practices, or any other conversation that would benefit from being searchable:\n\n[Discussions on GitHub](https://github.com/stacksjs/pngx/discussions)\n\nFor casual chit-chat with others using this package:\n\n[Join the Stacks Discord Server](https://discord.gg/stacksjs)\n\n## Postcardware\n\n“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where `pngx` is being used! We showcase them on our website too.\n\nOur address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094, United States 🌎\n\n## Credits\n\nMany thanks to [`pngjs`](https://github.com/pngjs/pngjs) and its contributors for inspiring this project.\n\n## Sponsors\n\nWe would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.\n\n- [JetBrains](https://www.jetbrains.com/)\n- [The Solana Foundation](https://solana.com/)\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.\n\nMade with 💙\n\n\u003c!-- Badges --\u003e\n[npm-version-src]: https://img.shields.io/npm/v/pngx?style=flat-square\n[npm-version-href]: https://npmjs.com/package/pngx\n[github-actions-src]: https://img.shields.io/github/actions/workflow/status/stacksjs/pngx/ci.yml?style=flat-square\u0026branch=main\n[github-actions-href]: https://github.com/stacksjs/pngx/actions?query=workflow%3Aci\n\n\u003c!-- [codecov-src]: https://img.shields.io/codecov/c/gh/stacksjs/pngx/main?style=flat-square\n[codecov-href]: https://codecov.io/gh/stacksjs/pngx --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fpngx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstacksjs%2Fpngx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstacksjs%2Fpngx/lists"}