{"id":20293002,"url":"https://github.com/gemini-testing/png-img","last_synced_at":"2025-04-11T11:32:03.479Z","repository":{"id":21659740,"uuid":"24980615","full_name":"gemini-testing/png-img","owner":"gemini-testing","description":"Lite libpng wrapper for node.js","archived":false,"fork":false,"pushed_at":"2022-10-11T07:35:21.000Z","size":3019,"stargazers_count":28,"open_issues_count":7,"forks_count":13,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-25T07:51:10.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/gemini-testing.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}},"created_at":"2014-10-09T08:40:21.000Z","updated_at":"2025-03-02T14:07:18.000Z","dependencies_parsed_at":"2022-07-27T02:47:18.151Z","dependency_job_id":null,"html_url":"https://github.com/gemini-testing/png-img","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-testing%2Fpng-img","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-testing%2Fpng-img/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-testing%2Fpng-img/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gemini-testing%2Fpng-img/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gemini-testing","download_url":"https://codeload.github.com/gemini-testing/png-img/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339267,"owners_count":21087214,"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":[],"created_at":"2024-11-14T15:20:39.486Z","updated_at":"2025-04-11T11:32:03.451Z","avatar_url":"https://github.com/gemini-testing.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"png-img\n=======\n\n[![Build Status](https://travis-ci.org/gemini-testing/png-img.svg)](https://travis-ci.org/gemini-testing/png-img)\n\nLite self-contained png image processing library for macOS and Linux.\n\n## Requirements\n### Linux\n- Depends on [GCC](https://gcc.gnu.org/) 4.6+\n\n### macOs\n- Tested with Xcode 6.0 (but should also work with 5.0) and Xcode 11.3\n- [`node-gyp` installation docs](https://github.com/nodejs/node-gyp#on-macos)\n- [`node-gyp` installation docs for Calalina](https://github.com/nodejs/node-gyp/blob/master/macOS_Catalina.md)\n\n### Windows\n- Tested with MSVC 2013 Express\n- [`node-gyp` installation docs](https://github.com/nodejs/node-gyp#on-windows)\n\n## Installation\n```\nnpm install png-img\n```\n\n## API\n### new PngImg(buffer)\nCreate `PngImg` object from passed buffer with image.\n\nArguments:\n * `buf` - `Buffer` with image file content.\n```js\nconst fs = require('fs');\nconst {PngImg} = require('png-img');\n\nconst buf = fs.readFileSync('path/to/img.png');\nconst img = new PngImg(buf);\n```\n\n### size()\nGet image size as an object.\n```js\nconsole.log(img.size());\n```\nfor 32x32 image will print out:\n```\n{ width: 32, height: 32 }\n```\n\n### get(x, y)\nGet pixel color and alpha.\n\nReturns object:\n * r: red channel (0 to 255)\n * g: green channel (0 to 255)\n * b: blue channel (0 to 255)\n * a: alpha (0 to 255). 0 - transparent\n\n```js\nconsole.log(img.get(0, 0));\n```\nwill print pixel and color for pixel (0, 0):\n```js\n{\n  r: 100,\n  g: 150,\n  b: 200,\n  a: 255\n}\n```\n\n### fill(offsetX, offsetY, widht, height, color)\nFill region with passed color. Modifies current image.\n\nArguments:\n * `offsetX` - horizontal offset from the left side of the image\n * `offsetY` - vertical offset from the top side of the image\n * `width` - region width\n * `height` - region height\n * `color` - color as {r,g,b,a} object or as a '#XXXXXX' string\n\nReturns: current image object\n\nThrows if region is not inside the current image\n```js\nimg\n  .fill(0, 0, 16, 16, '#00ffFF') // fill with cyan\n  .fill(16, 16, 16, 16, {r: 0, g: 255, b: 255, a: 127}); // fill with half-transparent cyan\n```\n\n### set(x, y, color)\nSame as `fill(x, y, 1, 1, color)`\n\n### crop(offsetX, offsetY, widht, height)\nCrop image. Modifies current image.\n\nArguments:\n * `offsetX` - horizontal offset from the left side of the image\n * `offsetY` - vertical offset from the top side of the image\n * `width` - new width\n * `height` - new height\n\nReturns: current image object\n\nThrows if new image is not inside the current image.\n```js\nimg\n    .crop(0, 0, 16, 16)\n    .crop(8, 8, 8, 8);\n```\n\n### setSize(width, height)\nSets new image size. Modifies current image.\n\nArguments:\n * `width` - new width\n * `height` - new height\n\nReturns: current image object\n\nIf new size is less or equal than current size, than `crop` will be performed.\n\n**Note**: this method doesn't strech current image, it just sets new size. If new dimension is less than previous\nthan image will be cut. If new dimension is greater than previous than image will be extended with black area.\n```js\nvar size = img.size();\nimg\n  .setSize(size.width/2, size.height*2);\n```\n\n### insert(img, offsetX, offsetY)\nInserts image into specified place.\n\nArguments:\n * `img` - image to insert. Should be a PngImg object\n * `offsetX` - horizontal offset from the left side of the image\n * `offsetY` - vertical offset from the top side of the image\n\nJoin to images (pretend that they have same witdh):\n ```js\nvar otherImg = new PngImg(/*...*/)\nimg\n  .setSize(img.size().width, img.size().height + otherImg.size().height)\n  .insert(otherImg, 0, img.size().height);\n ```\n\n### rotateRight()\nRotates image 90 degrees clockwise\n\n### rotateLeft()\nRotates image 90 degress counterclockwise\n\n### save(file)\nSave image to file. Asynchronous operation.\n\nArguments:\n * `file` - path to file to save image\n\nOverwrites existing file.\n\n```js\nawait img.save('path/to/file.png');\n```\n\n## Build\n```\nnpm run build\n```\nThis will build native node extension and place it to the `compiled` directory\n\n## Release\n1. Up version in package json, create tag, and push it to repo. **Note**: Do not publish the package.\n```\n$ npm version \u003cpatch|minor|major\u003e\n$ git push \u0026\u0026 git push --tags\n```\n2. Go to [tags page](https://github.com/gemini-testing/png-img/tags) and create release from pushed tag.\n3. Wait for the release workflow to finish. See the [actions page](https://github.com/gemini-testing/png-img/actions) to find the workflow.\n\n## Vagrant\nUse [Vagrant](https://www.vagrantup.com/) to build and test on Linux and Windows from macOS.\n\nTested with Vagrant 1.7 and [VirtualBox](https://www.virtualbox.org/) 4.3.\n\n1. Install Vagrant and VirtualBox.\n2. Create Windows vagrant box (see [howto](dev/vagrant-win-box.md))\n3. Run `vagrant up --provider virtualbox`\n4. Specify `OS` env variable to run and test on specific platform:\n  - `npm run build`, `npm test` - current platform\n  - `OS=linux npm test` - [Ubuntu](https://ubuntu.com/) 14.04\n  - `OS=linux-old npm test` - Ubuntu 12.04\n  - `OS=win npm test` - Windows\n  - `OS=all npm test` - all\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemini-testing%2Fpng-img","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgemini-testing%2Fpng-img","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgemini-testing%2Fpng-img/lists"}