Remige is a forked version of libSquoosh, integrating Squoosh's image codecs directly into your JavaScript applications. This fork ensures continued support and enhancements, compatible with the latest Node.js versions for optimal performance in modern development environments.
Remige supports the latest Node.js versions, ensuring compatibility and optimal performance in modern development environments.
With ongoing updates and improvements, Remige serves developers seeking robust image compression solutions within their JavaScript projects. It maintains functionality and reliability for current development practices.
Install Remige in your local project with:
$ npm install remige
To use Remige, import ImagePool
and set up your image processing pipeline:
import { ImagePool } from "remige";
import { cpus } from "os";
const imagePool = new ImagePool(cpus().length);
Ensure to only create one ImagePool
instance to avoid memory issues during parallel image processing.
Ingest images using imagePool.ingestImage()
, accepting ArrayBuffer
from fs.readFile()
or fetch()
.
import fs from "fs/promises";
const file = await fs.readFile("./path/to/image.png");
const image = imagePool.ingestImage(file);
Preprocess and encode images to various formats:
const preprocessOptions = {
resize: {
width: 100,
height: 50,
},
};
await image.preprocess(preprocessOptions);
const encodeOptions = {
mozjpeg: {}, // default settings
jxl: {
quality: 90,
},
};
const result = await image.encode(encodeOptions);
Close the ImagePool
pipeline to prevent ingesting and encoding new images:
await imagePool.close();
Write encoded images to the file system:
const rawEncodedImage = image.encodedWith.mozjpeg.binary;
await fs.writeFile("/path/to/new/image.jpg", rawEncodedImage);
Extract decoded and encoded image information:
console.log(await image.decoded);
console.log(image.encodedWith.jxl);
Remige includes an experimental auto optimizer:
const encodeOptions = {
mozjpeg: "auto",
};