{"id":15612276,"url":"https://github.com/kylefox/js-image-filters","last_synced_at":"2025-04-04T11:43:21.278Z","repository":{"id":66575051,"uuid":"2476251","full_name":"kylefox/js-image-filters","owner":"kylefox","description":"Experimental image filtering with Canvas \u0026 CoffeeScript","archived":false,"fork":false,"pushed_at":"2012-01-21T21:45:43.000Z","size":280,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T21:32:48.460Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","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/kylefox.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}},"created_at":"2011-09-28T16:40:21.000Z","updated_at":"2013-01-04T08:07:37.000Z","dependencies_parsed_at":"2023-02-20T07:00:25.946Z","dependency_job_id":null,"html_url":"https://github.com/kylefox/js-image-filters","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/kylefox%2Fjs-image-filters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fjs-image-filters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fjs-image-filters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kylefox%2Fjs-image-filters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kylefox","download_url":"https://codeload.github.com/kylefox/js-image-filters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174377,"owners_count":20896074,"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-10-03T06:41:17.548Z","updated_at":"2025-04-04T11:43:21.262Z","avatar_url":"https://github.com/kylefox.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Allows you to sequentially apply filters to images (`Image` or `HTMLImageElement`). These are just basic experiments with modifying image data using the `canvas` element. The code is written in CoffeeScript, but can be used with normal JavaScript.\n\n_The demo works best in Safari because other browsers have security limitations that prevent them accessing image data from local files. Things will work fine if the images/scripts are served off the same domain, however._\n\nBasic Use\n=========\n\n`Image.filter` allows you to pass an arbitrary number of filters and returns the processes `ImageData`:\n\n    // Markup: \u003cimg id=\"image\" src=\"demo.jpg\" /\u003e\n    var image = document.getElementById('img');\n    var output = image.filter(new GreyscaleFilter());\n    \nFor the time being, it's up to you to do something interesting with the output, like paint it on a canvas context:\n    \n    context.putImageData(output, 0, 0);\n    \nThis example shows how you can apply as many filters as you want:\n\n    var output = image.filter(\n      new GreyscaleFilter(),\n      new InvertFilter()\n    );\n    \nRight now there are only three filters (`GreyscaleFilter`, `InvertFilter`, and `OpacityFilter`) but I hope to add more -- or feel free to contribute your own :)\n\nFilter Settings\n===============\n\n`OpacityFilter` accepts a transparency factor:\n\n    # Reduce opacity to 75%\n    filter = new OpacityFilter({factor: 0.75});\n\n`GreyscaleFilter` accepts RGB weights:\n\n    # Give higher weight to the red channels.\n    filter = new GreyscaleFilter({r: .50, g: 0.25, b: 0.25})\n    \nDefining a Filter\n=================\n\nCreating a filter is super easy. All you need to do is extend the base `Filter` class and override the `processPixel` method. This example shows how you could modify the alpha channel to reduce opacity by 50%:\n\n    class HalfOpacityFilter extends Filter\n        processPixel: (buffer, offset) =\u003e\n            buffer[offset + 3] *= 0.5\n            \n`processPixel` takes two arguments:\n\n* `buffer` : the full array of pixel data\n* `offset` : the index of the next red channel to process\n\nYou can use `offset` to access the RGBA data for the current pixel:\n\n    processPixel: (buffer, offset) =\u003e\n        buffer[offset]          # Red channel\n        buffer[offset + 1]      # Green channel\n        buffer[offset + 2]      # Blue channel\n        buffer[offset + 3]      # Alpha channel\n\nEach element in the buffer is a byte ranging from 0-255.\n\nIf you want more granular control over how a filter is applied, just have your filter override `process(image_data)`.\n\nContributing\n============\n\nI'd love bug fixes, performance improvements, new filters \u0026 API suggestions. Just send me a message or pull request on GitHub and I'll get back to you.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefox%2Fjs-image-filters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkylefox%2Fjs-image-filters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkylefox%2Fjs-image-filters/lists"}