{"id":22040362,"url":"https://github.com/inventsable/getpixelcolor","last_synced_at":"2025-06-30T22:05:27.393Z","repository":{"id":153899201,"uuid":"629806100","full_name":"Inventsable/getPixelColor","owner":"Inventsable","description":"Illustrator script to retrieve RGBA values of any PlacedItem regardless of format (PNG, JPG, etc) by parsing raw binary, all from scratch in pure JS","archived":false,"fork":false,"pushed_at":"2023-04-20T12:47:01.000Z","size":23,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T22:02:31.268Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Inventsable.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2023-04-19T04:12:03.000Z","updated_at":"2025-05-31T18:32:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"813871ba-9461-4178-905c-5b9d820a8e7f","html_url":"https://github.com/Inventsable/getPixelColor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Inventsable/getPixelColor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inventsable%2FgetPixelColor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inventsable%2FgetPixelColor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inventsable%2FgetPixelColor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inventsable%2FgetPixelColor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Inventsable","download_url":"https://codeload.github.com/Inventsable/getPixelColor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Inventsable%2FgetPixelColor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262857258,"owners_count":23375487,"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-30T11:14:14.681Z","updated_at":"2025-06-30T22:05:27.307Z","avatar_url":"https://github.com/Inventsable.png","language":"JavaScript","readme":"# getPixelColor\n\nRetrieve RGB values of any PlacedItem regardless of format by parsing raw binary, all in pure scripting.\n\n\u003e [By request on the Illustrator forums](https://community.adobe.com/t5/illustrator-discussions/scripting-tools-to-get-the-color-of-a-particular-dot-placed-placed-on-an-image-layer/td-p/13727767)\n\nGiven any image within the Illustrator canvas, like a very ugly 3x3 pixel PNG:\n\n![](./assets/gridA.png)\n\nGrab the RGB values of any given pixel, list of pixels, or entire image. Note that coordinates are 0-based and top-down:\n\n![](./assets/gridB.png)\n\n## getPixelColor(pixels?: number[]|null, options?: \\\u003cOptions\\\u003e)\n\nAll `options` are optional, with default values being:\n\n```js\n{\n  // Function called at the very end of execution\n  onComplete: null,\n  // Function to modify binary data before parsing begins\n  onBeforeParse: null,\n  // Function to return parsed binary rawdata\n  onAfterParse: null,\n  BMP: {\n    // File location of temporary image\n    imagePath: Folder.userData + \"/pixelGetColor.BMP\",\n    // Whether image is automatically deleted after use\n    deleteImage: true,\n    // File location of temporary action\n    actionPath: Folder.userData + \"/exportBMP.aia\",\n    // Whether action is automatically deleted after use\n    deleteAction: true,\n  },\n  // Whether to return as native RGBColor or if false, as JSON\n  returnColor: true,\n  // Whether to return from parsing containing metadata about file such as width and height\n  verbose: false,\n  // Whether to remove duplicate colors\n  removeDuplicates: true,\n  // Whether to, if only one color is found, return the color directly instead of a 1-length array\n  flattenResults: true,\n}\n```\n\n## Examples using above 3x3 PNG:\n\n### Reading a single pixel:\n\n```js\ngetPixelColor([0, 1], {\n  // Easily write yourself a log via lifecycle hooks:\n  onAfterParse: function (result) {\n    alert(result); // [{\"r\":53,\"g\":255,\"b\":29,\"a\":0}]\n    // This function is not included but simple to make:\n    writeFile(\n      Folder.userData + \"/results.json\",\n      JSON.stringify(result) // JSON is also not included, just for demonstration\n    );\n  },\n});\n```\n\n### Reading multiple pixels, with additional metadata:\n\n```js\ngetPixelColor(\n  [\n    [0, 1],\n    [1, 1],\n  ],\n  {\n    verbose: true,\n    onAfterParse: function (result) {\n      writeFile(\n        Folder.userData + \"/results.json\",\n        JSON.stringify(result) // JSON is also not included, just for demonstration\n      );\n    },\n  }\n);\n```\n\n```json\n{\n  \"width\": 3,\n  \"height\": 3,\n  \"bpp\": 4,\n  \"bitDepth\": 32,\n  \"pixelData\": [\n    { \"r\": 53, \"g\": 255, \"b\": 29, \"a\": 0 },\n    { \"r\": 29, \"g\": 203, \"b\": 255, \"a\": 0 }\n  ]\n}\n```\n\n### Reading every pixel of the canvas:\n\n```js\ngetPixelColor(null, {\n  onAfterParse: function (result) {\n    writeFile(Folder.userData + \"/results.json\", JSON.stringify(result));\n  },\n});\n```\n\n```json\n[\n  { \"r\": 246, \"g\": 40, \"b\": 255, \"a\": 0, \"x\": 0, \"y\": 0 },\n  { \"r\": 255, \"g\": 184, \"b\": 44, \"a\": 0, \"x\": 1, \"y\": 0 },\n  { \"r\": 100, \"g\": 100, \"b\": 100, \"a\": 0, \"x\": 2, \"y\": 0 },\n  { \"r\": 53, \"g\": 255, \"b\": 29, \"a\": 0, \"x\": 0, \"y\": 1 },\n  { \"r\": 29, \"g\": 203, \"b\": 255, \"a\": 0, \"x\": 1, \"y\": 1 },\n  { \"r\": 251, \"g\": 127, \"b\": 127, \"a\": 0, \"x\": 2, \"y\": 1 },\n  { \"r\": 255, \"g\": 255, \"b\": 255, \"a\": 0, \"x\": 0, \"y\": 2 },\n  { \"r\": 0, \"g\": 0, \"b\": 0, \"a\": 0, \"x\": 1, \"y\": 2 },\n  { \"r\": 0, \"g\": 0, \"b\": 255, \"a\": 0, \"x\": 2, \"y\": 2 }\n]\n```\n\n\u003e Note the Y values here aren't correct and are inverted. This is due to BMP encoding being linear from left \u003e right and bottom \u003e top. Will fix this soon but running out of time on a weekday.\n\n### Getting every color of the canvas:\n\n```js\ngetPixelColor(null, {\n  /* \n    Since returnColor is true by default, onComplete lifecycle acts similar to onAfterParse with the \n    exception that it processes the results (like removing duplicates and transforming to vanilla colors)\n  */\n  onComplete: function (result) {\n    writeFile(Folder.userData + \"/results.json\", JSON.stringify(result));\n  },\n});\n```\n\n```js\n[\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n  [RGBColor],\n];\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finventsable%2Fgetpixelcolor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finventsable%2Fgetpixelcolor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finventsable%2Fgetpixelcolor/lists"}