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

image-utility-library

v1.1.0

Published

A Node.js library for compressing, resizing, cropping, and applying effects to images.

Readme


📸 Image Utility Library

A powerful, lightweight image processing library for Node.js. Easily compress, crop, resize, convert formats, apply effects, and export images in bulk with high performance.


🚀 Features

  • Image Compression – Reduce file sizes while maintaining quality
  • ✂️ Cropping – Crop images to specific dimensions
  • 📏 Resizing – Resize images to custom dimensions
  • 🎨 Format Conversion – Convert images between formats (JPEG, PNG, WebP)
  • 🌈 Effects – Apply effects like grayscale, invert, and sepia
  • Caching – Cache frequently processed images for faster performance
  • 📦 ZIP Export – Export multiple processed images into a ZIP archive

📦 Installation

Install the library using NPM:

npm install image-utility-lib

📂 Usage

First, import the functions into your project:

CommonJS

const {
  compressImage,
  cropImage,
  resizeImage,
  formatImage,
  applyEffects,
  cacheImage,
  getCachedImage,
  exportAsZip
} = require('image-utility-lib');

ES6

import {
  compressImage,
  cropImage,
  resizeImage,
  formatImage,
  applyEffects,
  cacheImage,
  getCachedImage,
  exportAsZip
} from 'image-utility-lib';

➡️ Examples

📉 1. Compress an Image

const fs = require('fs');

const imageBuffer = fs.readFileSync('input.jpg');

compressImage(imageBuffer, 50).then((compressed) => {
  fs.writeFileSync('output-compressed.jpg', compressed);
});

✂️ 2. Crop an Image

cropImage(imageBuffer, 300, 300).then((cropped) => {
  fs.writeFileSync('output-cropped.jpg', cropped);
});

📏 3. Resize an Image

resizeImage(imageBuffer, 800, 600).then((resized) => {
  fs.writeFileSync('output-resized.jpg', resized);
});

🖼️ 4. Convert Image Format

formatImage(imageBuffer, 'png').then((converted) => {
  fs.writeFileSync('output-converted.png', converted);
});

🎨 5. Apply Effects

applyEffects(imageBuffer, 'sepia').then((effectApplied) => {
  fs.writeFileSync('output-sepia.jpg', effectApplied);
});

Available effects:

  • grayscale
  • invert
  • sepia

6. Cache Processed Images

cacheImage('unique-key', compressed);

// Retrieve cached image
const cachedImage = getCachedImage('unique-key');
if (cachedImage) {
  console.log('Image retrieved from cache!');
}

📦 7. Export Images as ZIP

exportAsZip(
  [
    { name: 'compressed.jpg', buffer: compressed },
    { name: 'resized.jpg', buffer: resized }
  ],
  'output-images.zip'
).then(() => {
  console.log('Images exported as ZIP successfully!');
});

📋 API Reference

🔥 Image Processing Functions

compressImage(imageBuffer, quality) → Promise<Buffer>
  • imageBuffer: Buffer – The input image data
  • quality: Number – Compression quality (1–100)
cropImage(imageBuffer, width, height) → Promise<Buffer>
  • width: Number – Width of the cropped area
  • height: Number – Height of the cropped area
resizeImage(imageBuffer, width, height) → Promise<Buffer>
  • width: Number – New width
  • height: Number – New height
formatImage(imageBuffer, format) → Promise<Buffer>
  • format: String – Target format (jpeg, png, webp)
applyEffects(imageBuffer, effect) → Promise<Buffer>
  • effect: String – Image effect (grayscale, invert, sepia)

Caching Functions

cacheImage(key, imageBuffer)
  • key: String – Unique identifier for caching
  • imageBuffer: Buffer – The processed image to store
getCachedImage(key) → Buffer|null
  • Retrieves an image from the cache, if available

📦 Export Functions

exportAsZip(images, outputPath) → Promise<void>
  • images: Array – List of { name: String, buffer: Buffer } objects
  • outputPath: String – Output path for the ZIP file

🛠️ Requirements

  • Node.js v14+
  • Supported formats: JPEG, PNG, WebP

🐛 Contributing

  1. Fork the repository
  2. Create a new branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -m 'Add new feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a pull request 🚀

📜 License

This project is licensed under the MIT License.


👨‍💻 Author

Developed by Ayushman Gupta 🚀


🙌 Acknowledgments

  • Built using sharp, jimp, imagemin, and node-cache.
  • Inspired by the need for an efficient and versatile image utility library.