[![Latest version](https//github.com/onigoetz/resquoosh/releases) ![License](https://img.shields.io/github/license/onigoetz/resquoosh?style=flat-square) ![GitHub Workflow St
APACHE-2.0 License
Resquoosh is a fork of @squoosh/lib
.
But copied from Vercel's fork.
This version has a simple API.
import fs from "node:fs/promises";
import { optimizeImage, getImageSize } from "@onigoetz/resquoosh";
const file = await fs.readFile("file.jpg");
const size = await getImageSize(file);
console.log(size); // { width: 400, height: 400 }
const optimized = await optimizeImage(file);
// returns an optimized buffer
getImageSize(buffer: Buffer) => Promise<{ width: number, height: number }>
Get the size of an image within a Buffer
.
Supports the same formats as image-size
+ AVIF.
optimizeImage(buffer: Buffer, options: OptimizeOptions) => Promise<Buffer>
Compresses images, optionally resize or rotate the image.
interface OptimizeOptions {
/**
* Value between 1 and 100
*/
quality?: number;
/**
* If only width is specified; will resize and respect ratio
*/
width?: number;
/**
* If only height is specified; will resize and respect ratio
*/
height?: number;
}