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 🙏

© 2024 – Pkg Stats / Ryan Hefner

img-compressor-com

v1.0.2

Published

Compress images for web use with quality comparison and file size savings calculation.

Downloads

137

Readme

Intelligent Image Compressor with Quality Comparison

An efficient CLI and API tool for compressing images, with options for lossy and lossless compression, format conversion, batch processing, and interactive visual comparisons.

Features

  • Multi-Format Support: Supports popular image formats like JPEG, PNG, WebP, and TIFF.
  • Format Conversion: Convert images to different formats, such as PNG to WebP or JPEG.
  • Compression Options:
    • Lossless Compression: Retains original quality.
    • Lossy Compression: Allows customizable compression levels and quality.
  • Compression Levels: Use preset compression levels (high, medium, low) for convenient lossy compression.
  • Custom Quality Setting: Define specific quality (1-100) for finer control.
  • Batch Processing: Compress multiple images in one command.
  • Savings Report: Displays original size, compressed size, size reduction, and estimated load time improvements.
  • Before and After Visual Comparison: Generates an HTML preview with a slider to compare compressed and original images.
  • Command-Line Interface (CLI): Accessible through the command line for seamless integration into workflows.
  • Programmatic API: Can be integrated into Node.js projects for automated image optimization.

Installation

For CLI Usage

Install the package globally:

npm install -g img-compressor-com

For Programmatic Use

Install the package locally to use it as a library in your Node.js project:

npm install img-compressor-com

CLI Usage

After installation, the CLI can be used with the following commands:

Compress a Single Image

img-compressor-com compress <input> <output> [options]

Arguments:

  • <input>: Path to the input image.
  • <output>: Path where the compressed image will be saved.

Options:

  • -c, --convert-to <format>: Convert to a specific format (jpeg, png, webp, tiff). Default is jpeg.
  • -t, --compression-type <type>: Compression type (lossy or lossless). Default is lossy.
  • -l, --compression-level <level>: Compression level (high, medium, low).
  • -q, --quality <quality>: Quality level for compression (1-100).
  • -p, --generate-preview: Generates a before-and-after preview HTML file.

Example:

img-compressor-com compress input.jpg output_folder/ -c webp -t lossy -l high -q 80 -p

Batch Compress Images

img-compressor-com compress-batch <input> <output> [options]

Arguments:

  • <input>: Path to the input directory or a comma-separated list of file paths.
  • <output>: Path where the compressed images will be saved.

Options:

  • -c, --convert-to <format>: Format to convert the images to (e.g., jpeg, png, webp, tiff).
  • -t, --compression-type <type>: Compression type (lossy or lossless).
  • -l, --compression-level <level>: Compression level (high, medium, low).
  • -q, --quality <quality>: Quality level for compression (1-100).
  • -p, --generate-preview: Generates HTML comparison previews for each image.
  • -y, --concurrency <number>: Number of concurrent compression tasks. Default is 5.

Example:

img-compressor-com compress-batch input_folder output_folder -c png -t lossless -y 10 -p

Programmatic API Usage

Importing and Using in Code

You can also use the compression functions directly in your JavaScript or TypeScript code.

const { compressImage, compressImages } = require('img-compressor-cli');

// Compress a single image
compressImage('path/to/input.jpg', 'path/to/output', {
  convertTo: 'webp',
  compressionType: 'lossy',
  quality: 80,
  generatePreview: true,
})
  .then(stats => console.log('Compression stats:', stats))
  .catch(error => console.error('Error:', error));

// Compress multiple images in batch
compressImages('path/to/input/folder', 'path/to/output/folder', {
  convertTo: 'jpeg',
  compressionType: 'lossless',
  concurrency: 5,
})
  .then(results => console.log('Batch compression results:', results))
  .catch(error => console.error('Error:', error));

Output Statistics

Each compression operation returns statistics such as:

  • Original Size: Size of the original file in KB.
  • Compressed Size: Size of the compressed file in KB.
  • Size Reduced By: Percentage reduction in size.
  • Estimated Load Time Improvements: Estimated load time improvements based on compressed file size.

License

This project is licensed under the MIT License.