{"id":28089504,"url":"https://github.com/li-na/optipng.js","last_synced_at":"2025-08-01T23:38:52.786Z","repository":{"id":57315896,"uuid":"132803001","full_name":"LI-NA/optipng.js","owner":"LI-NA","description":"The native javascript png optimizer. Live demo:","archived":false,"fork":false,"pushed_at":"2018-05-14T00:18:36.000Z","size":3030,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T15:34:04.409Z","etag":null,"topics":["emscripten","image-processing","javascript","nodejs","optimization","optimizer","optipng","png"],"latest_commit_sha":null,"homepage":"https://li-na.github.io/optipng.js/","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/LI-NA.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":"2018-05-09T19:21:37.000Z","updated_at":"2025-02-12T20:50:16.000Z","dependencies_parsed_at":"2022-08-25T20:40:39.572Z","dependency_job_id":null,"html_url":"https://github.com/LI-NA/optipng.js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/LI-NA/optipng.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-NA%2Foptipng.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-NA%2Foptipng.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-NA%2Foptipng.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-NA%2Foptipng.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LI-NA","download_url":"https://codeload.github.com/LI-NA/optipng.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LI-NA%2Foptipng.js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265815979,"owners_count":23833052,"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":["emscripten","image-processing","javascript","nodejs","optimization","optimizer","optipng","png"],"created_at":"2025-05-13T12:59:11.118Z","updated_at":"2025-07-18T19:06:36.841Z","avatar_url":"https://github.com/LI-NA.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optipng.js\nOptipng.js is the port of [optipng](http://optipng.sourceforge.net/) in javascript using [emscripten](https://github.com/kripken/emscripten). You can optimize png image file without losing any information in the morden browser using Optipng.js.\n\nTip: Optipng version is 0.7.7.\n\n## API\n\n### `optipng(file, options, printFunction)`\n\n#### `file`\nPlease use binary file like readFile on node or Uint8Array (converted from base64) on javascript.\n```javascript\n// Node.js\nvar input = fs.readFileSync(\"input.png\");\nvar output = optipng(input, [\"-o2\"]);\n```\n```javascript\n// Browser\nfunction dataURLtoUint8(dataurl) {\n    var arr = dataurl.split(','),\n        mime = arr[0].match(/:(.*?);/)[1],\n        bstr = atob(arr[1]),\n        n = bstr.length,\n        u8arr = new Uint8Array(n);\n    while (n--) {\n        u8arr[n] = bstr.charCodeAt(n);\n    }\n    return u8arr;\n}\nfunction readFile (file, callback) {\n    var fileReader = new FileReader();\n    fileReader.onload = function() {\n        var ary = dataURLtoUint8(this.target.result);\n        callback(ary);\n    };\n    fileReader.readAsDataURL(file);\n}\n\nvar input, output;\nreadFile(your_file_on_here, function(ary) {\n    input = ary;\n    output = optipng(input, [\"-o2\"]);\n    // do something with output\n});\n```\n\n#### `options`\nOptions can be array or object.\n```javascript\nvar options = [\"-o2\", \"-i0\", \"-strip\", \"all\"];\nvar options = {o2: true, i0: true, strip: \"all\"};\n// Both options is same options. If use boolean in value, value will be ignored and only key will be inserted as options.\n```\n\n#### `printFunction`\nThis callback function is optional. It will be called if optipng will print something on stdout or stderr.\n```javascript\noptipng(input, [\"-o2\"], function(str) {\n    console.log(str);\n});\n```\n\n#### `return`\n```javascript\noutput = {\n    data: [output file],\n    stdout: [output string],\n    stderr: [error string]\n};\n```\n\n## Full Example\n\n### Node.js\n```\n$ npm i -S optipng-js\n```\n\n```javascript\nvar optipng = require(\"optipng-js\");\nvar fs = require(\"fs\");\n\nvar input = fs.readFileSync(\"input.png\");\nvar output = optipng(input, [\"-o2\"]);\n// var output = optipng(input, {\"o2\": true});\n/*\n    output = {\n        data: output file,\n        stdout: output string,\n        stderr: error string\n    }\n*/\n\nconsole.log(output.stdout);\nconsole.log(output.stderr);\n\nfs.writeFileSync(\"output.png\", output.data);\n```\n\n### Browser\nPlease check Demo with Web worker. [https://li-na.github.io/optipng.js/](https://li-na.github.io/optipng.js/)\n\n## Build\nActually, I don't know what it is but I made build shell script and it seems working. Please let me know if you have ANY better way to build this project.\n\nYou have to setup emscripten sdk on [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html) first.\n\nThen, download or clone this git on your linux computer. (Windows does not supported at this moment)\n```\n$ git clone https://github.com/LI-NA/optipng.js\n```\n\nFinally, just run `./build.sh`. It will configure optipng and compile with emcc.\n\n## License\n[MIT License](LICENSE)\n\nOptipng source code is under [zlib license](deps/optipng/LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-na%2Foptipng.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fli-na%2Foptipng.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fli-na%2Foptipng.js/lists"}