{"id":18415746,"url":"https://github.com/moritzsalla/canvas-image-filter","last_synced_at":"2025-04-13T02:30:51.943Z","repository":{"id":69487408,"uuid":"220322528","full_name":"moritzsalla/canvas-image-filter","owner":"moritzsalla","description":"Basic canvas pixel operations","archived":false,"fork":false,"pushed_at":"2021-05-29T11:55:52.000Z","size":1694,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-16T06:24:51.834Z","etag":null,"topics":["canvas","image-filter","javascript"],"latest_commit_sha":null,"homepage":"","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/moritzsalla.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}},"created_at":"2019-11-07T20:23:14.000Z","updated_at":"2022-02-02T21:22:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"f49e115b-2cc5-48f4-9b12-20af5a6fb14c","html_url":"https://github.com/moritzsalla/canvas-image-filter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moritzsalla%2Fcanvas-image-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moritzsalla%2Fcanvas-image-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moritzsalla%2Fcanvas-image-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moritzsalla%2Fcanvas-image-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moritzsalla","download_url":"https://codeload.github.com/moritzsalla/canvas-image-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657795,"owners_count":21140841,"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":["canvas","image-filter","javascript"],"created_at":"2024-11-06T03:55:01.085Z","updated_at":"2025-04-13T02:30:51.918Z","avatar_url":"https://github.com/moritzsalla.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Performing Pixel Operations on HTML Canvas\n\n![Image of mountains by Dominik Lange](screenshot.png)\n\n```javascript\nposition=(x+y*imageData.width)*4;\nimageData.data[position] = c%255;\nimageData.data[position+1] = c%255;\nimageData.data[position+2] = c%255\nimageData.data[position+3] = 255;\n```\n\n```javascript\n// spits out a long list of values, with quadruples of red, green, blue and alpha channels\nimageData.data[]\n// [r, g, b, a, r, g, b, a, r, g, b, a…]\n```\n\n```javascript\n// first two lines of an image\n0   1  2  3  4  5\n6   7  8  9 10 11\n12 13 14 15 16 17\n\n// we can now derive this useful formula from this observation\n// to find a specific pixel, this formula has to be used\nx + y * width\n4 + 12 * 6\n= 16\n\n(x + 1 * width) * 4\n```\n\n\n```javascript\n// we can skip alpha value like so\nfor (let i = 0, len = input.data.length; i \u003c len; i++) {\n    // skip canvas's alpha channel\n    if (i % 4 === 3) {\n      continue\n    }\n\n    // ...\n  }\n```\n\nGood resources:\n\n1. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Pixel_manipulation_with_canvas\n2. https://www.youtube.com/watch?v=nMUMZ5YRxHI\n3. https://www.youtube.com/watch?v=rNqaw8LT2ZU\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoritzsalla%2Fcanvas-image-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoritzsalla%2Fcanvas-image-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoritzsalla%2Fcanvas-image-filter/lists"}