{"id":13483491,"url":"https://github.com/stumpycr/stumpy_png","last_synced_at":"2025-04-14T16:24:33.381Z","repository":{"id":49567014,"uuid":"62754498","full_name":"stumpycr/stumpy_png","owner":"stumpycr","description":"Read/Write PNG images in pure Crystal","archived":false,"fork":false,"pushed_at":"2023-12-05T01:37:20.000Z","size":249,"stargazers_count":106,"open_issues_count":2,"forks_count":22,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T05:07:39.696Z","etag":null,"topics":["crystal","image-processing","png"],"latest_commit_sha":null,"homepage":"","language":"Crystal","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/stumpycr.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":"2016-07-06T21:27:55.000Z","updated_at":"2024-11-28T00:37:43.000Z","dependencies_parsed_at":"2024-05-02T20:08:39.113Z","dependency_job_id":null,"html_url":"https://github.com/stumpycr/stumpy_png","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stumpycr%2Fstumpy_png","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stumpycr%2Fstumpy_png/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stumpycr%2Fstumpy_png/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stumpycr%2Fstumpy_png/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stumpycr","download_url":"https://codeload.github.com/stumpycr/stumpy_png/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248915046,"owners_count":21182552,"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":["crystal","image-processing","png"],"created_at":"2024-07-31T17:01:11.887Z","updated_at":"2025-04-14T16:24:33.349Z","avatar_url":"https://github.com/stumpycr.png","language":"Crystal","funding_links":[],"categories":["Image processing"],"sub_categories":[],"readme":"# stumpy_png\n[![CI](https://github.com/stumpycr/stumpy_png/actions/workflows/ci.yml/badge.svg)](https://github.com/stumpycr/stumpy_png/actions/workflows/ci.yml)\n\n[Documentation](https://docs.leonrische.me/stumpy_png/)\n\n## Interface\n\n* `StumpyPNG.read(path : String) : Canvas` read a PNG image file from a path\n* `StumpyPNG.read(io : IO) : Canvas` read a PNG image file from any IO object\n* `StumpyPNG.write(canvas, path : String, bit_depth: 16, color_type: :rgb_alpha)` save a canvas as a PNG image file\n* `StumpyPNG.write(canvas, io : IO, bit_depth: 16, color_type: :rgb_alpha)` write a canvas as PNG data to any IO object\n  * `bit_depth` is optional, valid values are `8` and `16`(default)\n  * `color_type` is optional, valid values are `:grayscale`, `:grayscale_alpha`, `:rgb` and `:rgb_alpha`(default)\n* `StumpyPNG::PNG`, helper class to store some state while parsing PNG files\n* `Canvas` and `RGBA` from [stumpy_core](https://github.com/stumpycr/stumpy_core)\n\n## Usage\n\n### Install the `stumpy_png` shard\n\n1. `shards init`\n2. Add the dependency to the `shard.yml` file\n ``` yaml\n ...\n dependencies:\n   stumpy_png:\n     github: stumpycr/stumpy_png\n     version: \"~\u003e 5.0\"\n ...\n ```\n3. `shards install`\n\n### Reading\n\n``` crystal\nrequire \"stumpy_png\"\n\ncanvas = StumpyPNG.read(\"foo.png\")\nr, g, b = canvas[0, 0].to_rgb8\nputs \"red=#{r}, green=#{g}, blue=#{b}\"\n```\n\n### Writing\n\n``` crystal\nrequire \"stumpy_png\"\ninclude StumpyPNG\n\ncanvas = Canvas.new(256, 256)\n\n(0..255).each do |x|\n  (0..255).each do |y|\n    # RGBA.from_rgb_n(values, bit_depth) is an internal helper method\n    # that creates an RGBA object from a rgb triplet with a given bit depth\n    color = RGBA.from_rgb_n(x, y, 255, 8)\n    canvas[x, y] = color\n  end\nend\n\nStumpyPNG.write(canvas, \"rainbow.png\")\n```\n\n![PNG image with a color gradient](examples/rainbow.png)\n\n(See `examples/` for more examples)\n\n## Reading PNG files\n\n### Color Types\n\n- [x] Grayscale\n- [x] Grayscale + Alpha\n- [x] RGB\n- [x] RGB + Alpha\n- [x] Palette\n\n### Filter Types\n\n- [x] None\n- [x] Sub\n- [x] Up\n- [x] Average\n- [x] Paeth\n\n### Interlacing Methods\n\n- [x] None\n- [x] Adam7\n\n### Ancillary Chunks\n\nNone are supported right now.\n\n## Writing\n\n* RGB with 8 or 16 bits\n* RGB + Alpha with 8 or 16 bits\n* Grayscale with 8 or 16 bits\n* Grayscale + Alpha with 8 or 16 bits\n\n## Troubleshooting\n\nIf you run into errors like\n\n```bash\n/usr/bin/ld: cannot find -lz\ncollect2: error: ld returned 1 exit status\n```\n\nmake sure `zlib` is installed\n([Installing zlib under ubuntu](https://ubuntuforums.org/showthread.php?t=1528204)).\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore --\u003e\n| [\u003cimg src=\"https://avatars.githubusercontent.com/u/2788811?v=3\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eChris Hobbs\u003c/b\u003e\u003c/sub\u003e](https://github.com/rx14)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=RX14 \"Code\") | [\u003cimg src=\"https://avatars.githubusercontent.com/u/209371?v=3\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAry Borenszweig\u003c/b\u003e\u003c/sub\u003e](https://github.com/asterite)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=asterite \"Code\") | [\u003cimg src=\"https://avatars.githubusercontent.com/u/90345?v=3\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eAlex Muscar\u003c/b\u003e\u003c/sub\u003e](https://github.com/muscar)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=muscar \"Code\") | [\u003cimg src=\"https://avatars2.githubusercontent.com/u/18718?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDru Jensen\u003c/b\u003e\u003c/sub\u003e](https://github.com/drujensen)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=drujensen \"Code\") | [\u003cimg src=\"https://avatars3.githubusercontent.com/u/5798442?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003ekojix2\u003c/b\u003e\u003c/sub\u003e](https://github.com/kojix2)\u003cbr /\u003e[📖](https://github.com/l3kn/stumpy_png/commits?author=kojix2 \"Documentation\") | [\u003cimg src=\"https://avatars0.githubusercontent.com/u/4363779?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eobskyr\u003c/b\u003e\u003c/sub\u003e](http://obskyr.io/)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=obskyr \"Code\") | [\u003cimg src=\"https://avatars3.githubusercontent.com/u/35064754?v=4\" width=\"100px;\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003er00ster\u003c/b\u003e\u003c/sub\u003e](https://github.com/r00ster91)\u003cbr /\u003e[💻](https://github.com/l3kn/stumpy_png/commits?author=r00ster91 \"Code\") |\n| :---: | :---: | :---: | :---: | :---: | :---: | :---: |\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstumpycr%2Fstumpy_png","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstumpycr%2Fstumpy_png","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstumpycr%2Fstumpy_png/lists"}