resquoosh

[![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

Downloads
547
Stars
1

Resquoosh

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.

Supported formats

  • webp (Except animated webp)
  • avif
  • jpeg
  • png

Supported options

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;
}