{"id":"grilme99/png-luau","name":"png-luau","scope":"grilme99","platform":"roblox","description":"Luau library for working with PNG files","version":"0.2.1","latest":"0.2.1","versions":["0.2.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"01184c62e4faa9a15e31ceee910afb67622b8a44dfd7f758bf9e7ed3a290f294","likes":0,"downloads":0,"install":"forest install grilme99/png-luau","url":"https://forest.dev/p/roblox/grilme99/png-luau","files":"https://api.forest.dev/ai/package/roblox/grilme99/png-luau/files","readme":"# png-luau\n\nPNG encoder/decoder for Luau. The decoder supports all valid PNG files, bit depths, color types, interlacing, and transparency chunks.\n\n## Installation\n\nThis library is built for all Luau runtimes and Roblox projects.\n\n### Wally\n\nAdd `png-luau` to your `wally.toml`:\n\n```toml\npng-luau = \"sircfenner/png-luau@0.2.1\"\n```\n\n### Releases\n\nPre-built versions are available in [GitHub releases](https://github.com/sircfenner/png-luau/releases):\n\n- `png.luau` is a bundled single-file version of the library\n- `png.rbxm` is a Roblox model file\n\n## Decoding\n\nTo decode a PNG image, call the `decode` function with a buffer containing the file contents:\n\n```Luau\nlocal PNG = require(\"@vendor/png-luau\")\n\nlocal png = PNG.decode(file)\n```\n\nThis returns a table with the following type:\n\n```Luau\n{\n\twidth: number,\n\theight: number,\n\tpixels: buffer,\n\treadPixel: (x: number, y: number) -> (number, number, number, number)\n}\n```\n\nThe `pixels` buffer contains the decoded pixels in 32-bit RGBA format, top-to-bottom and left-to-right.\n\nThe `readPixel` function takes a pixel coordinate starting from (1, 1) in the top-left corner and returns the color information for that pixel (red, green, blue, alpha in the range 0-255).\n\nThe `decode` function takes an optional second parameter, which is a table specifying decoding options. Currently, the only valid option is `allowIncorrectCRC`, a boolean which defaults to false. It exists only for testing purposes and may be removed in future versions.\n\nKnown limitations:\n\n- Attempting to decode an invalid PNG file will throw an error\n- All ancillary chunks other than tRNS are currently skipped (other than CRC32 checks) when decoding\n- Images are transformed into 32-bit RGBA pixel data after decoding, regardless of original bit depth and color type\n- Files greater than 1GB in size or yielding greater than 1GB of image data after decompression (equivalent to ~16k x 16k resolution) cannot be decoded as they do not fit in a single Luau buffer\n\n## Encoding\n\nTo encode a PNG image, call the `encode` function with a buffer containing the pixel data in 32-bit RGBA format as well as a table containing `width` and `height`:\n\n```Luau\nlocal PNG = require(\"@vendor/png-luau\")\n\nlocal file = PNG.encode(pixelBuffer, {\n\twidth = 256,\n\theight = 128,\n})\n```\n\nThis returns a buffer containing the encoded PNG file.\n\nKnown limitations:\n\n- Pixel data for encoding must be in 32-bit RGBA format as described above\n- Images will be encoded in this same format - there is no support for writing other bit depths or color types\n- Encoded images will never be interlaced or use transparency chunks\n- As with decoding, the Luau buffer size cap of 1GB limits the maximum size of image data and encoded files\n\n## License\n\nThis project is available under the MIT license. See [LICENSE](LICENSE) for details.\n\nSome tests are derived from:\n\n- [pngsuite](http://www.schaik.com/pngsuite/pngsuite.html)\n- [imagetestsuite](https://code.google.com/archive/p/imagetestsuite/wikis/PNGTestSuite.wiki)\n- [javapng](https://github.com/kerner1000/javapng/tree/master)\n","readmeTruncated":false}