{"id":15650277,"url":"https://github.com/hg-pyun/node-image-filter","last_synced_at":"2025-04-30T16:45:51.032Z","repository":{"id":57311407,"uuid":"82378219","full_name":"hg-pyun/node-image-filter","owner":"hg-pyun","description":"Simple Image Filter for Node.js","archived":false,"fork":false,"pushed_at":"2018-11-20T14:22:38.000Z","size":284,"stargazers_count":36,"open_issues_count":8,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T20:16:45.817Z","etag":null,"topics":["filter","image-processing","javascript","nodejs"],"latest_commit_sha":null,"homepage":"","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/hg-pyun.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":"2017-02-18T10:11:23.000Z","updated_at":"2024-01-04T14:26:17.000Z","dependencies_parsed_at":"2022-09-10T21:13:33.089Z","dependency_job_id":null,"html_url":"https://github.com/hg-pyun/node-image-filter","commit_stats":null,"previous_names":["haegul/node-image-filter"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hg-pyun%2Fnode-image-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hg-pyun%2Fnode-image-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hg-pyun%2Fnode-image-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hg-pyun%2Fnode-image-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hg-pyun","download_url":"https://codeload.github.com/hg-pyun/node-image-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251747477,"owners_count":21637404,"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":["filter","image-processing","javascript","nodejs"],"created_at":"2024-10-03T12:34:10.118Z","updated_at":"2025-04-30T16:45:50.998Z","avatar_url":"https://github.com/hg-pyun.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-image-filter\n[![npm](https://img.shields.io/npm/v/node-image-filter.svg)](https://www.npmjs.com/package/node-image-filter)\n[![npm](https://img.shields.io/npm/dt/node-image-filter.svg)](https://www.npmjs.com/package/node-image-filter)\n[![GitHub license](https://img.shields.io/github/license/hg-pyun/node-image-filter.svg)](https://github.com/hg-pyun/node-image-filter/blob/master/LICENSE)\n\nImage Processing Library for nodejs.\n\n## Install\n```\n$ npm install node-image-filter --save\n```\n\n## Basic Usage\n### Render\nTo apply a filter, use the render function.\n```\nrender(imagePath, filter[, options], callback);\n```\nYou can use preset filters or custom filters. callback function receives result data. The data contains image buffer, type, width, height information.\nLet's look at the example.\n\n```javascript\nconst Filter = require('node-image-filter');\n\n// express\napp.use(function (req, res, next) {\n\n    let imagePath = path.join(__dirname, '../samples/cat.jpg');\n\n    Filter.render(imagePath, Filter.preset.invert, function (result) {\n        /* result format\n        {\n            data : stream,\n            type : 'jpg',\n            width : 1024,\n            height : 768\n        }\n        */\n        result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n        res.send('save filtered image');\n    })\n});\n```\n\n### Preset Filters\n`node-image-filter` includes Preset filters. There are currently four filters in total.\nYou just need to pass it as the second parameter of the Render function.\n```javascript\nconst Filter = require('node-image-filter');\n\n// filter list\nFilter.preset.invert\nFilter.preset.grayscale\nFilter.preset.sepia\nFilter.preset.brightness\n```\n\n### Custom Filter\nYou can also use your own filters. Pass the filter you created yourself as the second parameter.\nThe filter function takes pixels as a parameter and must process these pixels.data and return.\n\n```javascript\n// custom filter\nlet CustomInvertFilter = function (pixels) {\n    var data = pixels.data;\n    for(let i=0; i\u003cdata.length; i+=4 ){\n        data[i] = 255 - data[i];\n        data[i+1] = 255 - data[i+1];\n        data[i+2] = 255 - data[i+2];\n        data[i+3] = 255;\n    }\n    return data;\n};\n\nFilter.render(imagePath, CustomInvertFilter, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n    res.send('save filtered image');\n})\n```\n\nIf you want to pass options to a filter, Use the third parameter of the Render function.\n\n```javascript\n// custom filter with options\nfunction CustomBrightnessFilter (pixels, options){\n    var data = pixels.data;\n    var value = options.value || 5;\n\n    for(var i =0; i\u003c data.length; i+=4){\n        data[i] += value;\n        data[i+1] += value;\n        data[i+2] += value;\n    }\n    return data;\n}\n\n// third param for option.\nlet options = {\n    value : 10\n};\n\nFilter.render(imagePath, CustomBrightnessFilter, options, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n    res.send('save filtered image');\n})\n```\n\n## Convolution\n### Render\nYou can also use convolution theory such as sobel, sharpen, and others. Here are some examples.\n```javascript\n\n// sobel\nFilter.render(imagePath, Filter.preset.sobel, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n    res.send('save filtered image');\n})\n\n// sharpen\nFilter.render(imagePath, Filter.preset.sharpen, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n    res.send('save filtered image');\n})\n\n// blur\nlet options = {\n    value : 100\n};\n\nFilter.render(imagePath, Filter.preset.blur, options, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local\n    res.send('save filtered image');\n})\n```\n\n### Custom Convolution Filter\nThe usage is very similar to the custom filter. You can make convolution filter using `Filter.convolution(pixels, weights, opaque)`.\nAlso, You pass option using third parameter.\n```javascript\nfunction sobel(pixels) {\n    return Filter.convolution(pixels,\n           [-1, 0, 1,\n            -2, 0, 2,\n            -1, 0, 1], 1);\n}\n\nFilter.render(imagePath, sobel, function (result) {\n    result.data.pipe(fs.createWriteStream(`result.${result.type}`));\n    console.log('[DEV Server]', 'Saved Custom Sobel Image');\n});\n```\n\n# LICENSE\n\nCopyright (c) 2017 Haegul, PYUN  \n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhg-pyun%2Fnode-image-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhg-pyun%2Fnode-image-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhg-pyun%2Fnode-image-filter/lists"}