npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@srijanpokhrel/image-shrink

v1.0.3

Published

Compress AVIF, WebP, JPEG, and PNG images from the CLI or Node.js API — powered by [sharp](https://sharp.pixelplumbing.com/) (libvips).

Readme

image-shrink

Compress AVIF, WebP, JPEG, and PNG images from the CLI or Node.js API — powered by sharp (libvips).

Features

  • Compress JPEG, PNG, WebP, and AVIF
  • Convert between formats (e.g. JPEG → WebP)
  • Resize to a max width or height while preserving aspect ratio
  • Strip EXIF/GPS metadata
  • Batch compress via glob patterns
  • Use as a CLI tool or Node.js API

Install

# CLI (global install)
npm install -g @srijanpokhrel/image-shrink

# Node.js API (project dependency)
npm install @srijanpokhrel/image-shrink

Note: Remove the -g flag when installing as a project dependency.


CLI Usage

# Compress a single file (in-place)
image-shrink "photo.jpg"

# Batch compress all JPEGs in a folder
image-shrink "images/**/*.jpg"

# Convert to WebP with custom quality
image-shrink "images/**/*.jpg" --format webp --quality 80

# Resize to max 800px width and output to a folder
image-shrink "images/**/*.jpg" --width 800 --out dist/images

# Convert to AVIF
image-shrink "images/**/*.{jpg,png}" --format avif --quality 60

Options

| Flag | Default | Description | |------|---------|-------------| | --quality, -q | 80 | Compression quality, 1–100 | | --format, -f | auto | Output format: jpeg, png, webp, avif | | --out, -o | in-place | Output directory | | --width, -w | — | Max width in px, preserves aspect ratio | | --strip | true | Strip EXIF/GPS metadata |


Node.js API

import { compress } from 'image-shrink';
import fs from 'fs/promises';

const input = await fs.readFile('photo.jpg');

const result = await compress(input, {
  quality: 80,
  format: 'webp',
  stripMetadata: true,
});

await fs.writeFile('photo.webp', result.outputBuffer);

console.log(`Saved ${result.savedPercent}%`);
// → Saved 63%

compress(input, options)

| Option | Type | Default | Description | |--------|------|---------|-------------| | quality | number | 80 | Compression quality, 1–100 | | format | 'jpeg' \| 'png' \| 'webp' \| 'avif' | auto-detect | Output format | | width | number | — | Max width in px, preserves aspect ratio | | height | number | — | Max height in px, preserves aspect ratio | | stripMetadata | boolean | true | Strip EXIF/GPS metadata | | lossless | boolean | false | Lossless compression (WebP/AVIF only) | | effort | number | 4 | Compression effort, 0–9 (AVIF only) |

CompressResult

{
  inputSize: number;      // original size in bytes
  outputSize: number;     // compressed size in bytes
  savedBytes: number;     // bytes saved
  savedPercent: number;   // % reduction
  outputBuffer: Buffer;   // compressed image data
}

Real-World Results

Tested on a high-resolution JPEG (743 KB, 4500×3000 px):

| Command | Output | Saved | |---------|--------|-------| | --quality 75 | 104 KB | 86% | | --format webp --quality 80 | 78 KB | 89% | | --width 800 --quality 75 | 41 KB | 94% |

Results vary by image content. High-detail photos compress differently than flat graphics.


Local Development

git clone https://github.com/crizanp/image-shrink
cd image-shrink
npm install
npm run build

Run Manually

# Test the CLI directly (no global install needed)
node dist/cli.js "tests/fixtures/sample.jpg" --quality 80

# Watch mode — rebuilds on every save
npm run dev

Run Tests

npm test

# With coverage report
npm test -- --coverage

Test Results

PASS  tests/compress.test.ts
  compress()
    ✓ compresses JPEG and returns smaller output (310ms)
    ✓ converts to WebP (280ms)
    ✓ converts to AVIF (890ms)
    ✓ resizes to max width (200ms)
    ✓ strips EXIF metadata (195ms)
    ✓ savings stats are mathematically correct (190ms)
    ✓ throws on invalid input (12ms)

Tests: 7 passed  |  Time: ~2.5s

Scripts

| Command | Description | |---------|-------------| | npm run build | Compile TypeScript → dist/ | | npm run dev | Watch mode, rebuild on save | | npm test | Run Jest test suite | | npm test -- --coverage | Tests + coverage report |


License

MIT