oxipng-node

1.1.1 • Public • Published

oxipng-node CI npm version

Nodejs wrapper for multithreaded PNG optimizer written in Rust: oxipng

Installation

Execute command

npm i oxipng-node or yarn add oxipng-node

depending on your project package manager.

Usage

// 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 => { ... })
}

TypeScript Support

Package includes type definitions out the box.

Options

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

Package Sidebar

Install

npm i oxipng-node

Weekly Downloads

16

Version

1.1.1

License

MIT

Unpacked Size

7.31 kB

Total Files

6

Last publish

Collaborators

  • saionaro