All Projects → as-com → mozjpeg-js

as-com / mozjpeg-js

Licence: BSD-3-Clause license
Implementation of MozJPEG in pure JavaScript, using Emscripten

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects

mozjpeg-js

Implementation of MozJPEG in pure JavaScript, using Emscripten

Usage

$ npm i -S mozjpeg-js

Call mozjpeg.encode with a typed array or buffer of data and an arguments object:

const mozjpeg = require("mozjpeg-js");
const fs = require("fs");

const input = fs.readFileSync("in.ppm");
const out = mozjpeg.encode(input, { quality: 85 });
// out = { data: <mozjpeg output>, stderr: <cjpeg stderr> }

console.error(out.stderr);
fs.writeFileSync("out.jpg", out.data);

Alternatively, you may specify arguments as an array:

const input = fs.readFileSync("in.ppm");
const out = mozjpeg.encode(input, ["-quality", "85"]);
...

You may use any options available in mozjpeg's cjpeg command line utility.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].