Nodejs wrapper for multithreaded PNG optimizer written in Rust: oxipng
Execute command
npm i oxipng-node
or yarn add oxipng-node
depending on your project package manager.
// import module
const { run } = require("oxipng-node");
// import { run } from "oxipng-node"; // in case of TS
async function optimizeCat() {
try {
await run({
input: "/Users/user/project/images/cat.png",
out: "/Users/user/project/images/optimized/cat.png",
optimization: 2,
});
console.log("File optimized!");
} catch (e) {
console.error(e);
}
// you can also use it without async-await
// run(options).then(() => { ... }).catch(e => { ... })
}
Package includes type definitions out the box.
Name | Type | Default value | Description |
---|---|---|---|
path |
string |
- | Global path to file for optimization supports GLOBs |
out |
string |
- | Global path to output file, if missing will modify original file inplace |
optimization? |
number (1-6) |
2 | Optimization preset see here for details |
alpha? |
boolean |
false | Perform additional alpha optimizations |
interlacing? |
boolean |
false | PNG interlace type |
strip? |
"safe", "all" |
- | Strip metadata |