png-js is a JavaScript-based PNG decoder designed for both Node.js and browser environments. The package's latest version, 2.0.0, was released over a decade ago (tagged in 2013, with the last npm publish for version 1.0.0 being over six years ago), indicating it is an abandoned project with no active maintenance or release cadence. While it provides basic functionality for decoding PNG files into raw pixel data, its age means it does not support modern JavaScript module systems like ESM, lacks official TypeScript definitions, and likely misses performance optimizations or features found in contemporary image processing libraries. Developers requiring a robust, actively maintained, or high-performance PNG solution should consider modern alternatives such as 'pngjs' (note the lowercase 'js'), 'sharp', or 'jimp'. Its key differentiator was being a pure JavaScript decoder for both environments at a time when fewer options existed.
npm install png-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `png-js` in a Node.js-like environment to decode PNG files either by path or from a buffer, showing its callback-based asynchronous API. It mocks the actual file operations for runnable demonstration, as the library is old and CJS-only.
Migrate to actively maintained alternatives like `pngjs` (note the lowercase 'js'), `sharp`, or `jimp` for better security, performance, and modern feature support.
For Node.js ESM projects, you might need to use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const PNG = require('png-js');` or use a build step with a bundler like Webpack or Rollup that handles CJS modules. Consider using a modern ESM-compatible library instead.Manually create a declaration file (`png-js.d.ts`) with `declare module 'png-js' { ... }` or switch to a library that ships with its own types or has community-maintained `@types` packages.For performance-critical applications, especially in Node.js, evaluate libraries like `sharp` which utilize native code for speed. For browser, consider native browser APIs or newer JavaScript libraries optimized for performance (e.g., `UPNG.js`).
Use CommonJS `require()` syntax for Node.js: `const PNG = require('png-js');`. If in an ESM file, you may need `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const PNG = require('png-js');`.For browsers, ensure `<script src="png.js"></script>` and `<script src="zlib.js"></script>` are present before your script. For Node.js, ensure `const PNG = require('png-js');` is at the top of your file.Verify the integrity of the PNG file. If the file is valid and still causes issues, this library might not support that specific PNG variant. Consider using a more robust and actively maintained PNG decoding library like `pngjs` (lowercase) or `sharp`.
No dependency data recorded yet.