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

@codext/project-image-compression

v1.0.2

Published

A CLI tool for compressing and optimizing images in bulk in a npm project

Downloads

206

Readme

project-image-compression

A powerful and flexible CLI tool for bulk image compression and optimization. This tool helps you automatically compress and resize images in a directory while maintaining quality and optionally converting them to WebP format.

Features

  • 🖼️ Bulk image compression with customizable quality settings
  • ↔️ Automatic image resizing while maintaining aspect ratio
  • 🔄 Optional WebP conversion
  • 📁 Custom output directory support
  • 💾 Automatic backup creation
  • 📊 Detailed compression statistics
  • 🎯 Configurable via JSON file
  • 🚀 Support for JPG, JPEG, PNG, and WebP formats

Installation

npm install @codext/project-image-compression

Quick Start

  1. Add the script to your package.json:
{
  "scripts": {
    "compress-images": "npx @codext/project-image-compression"
  }
}
  1. Create an img.config.json file in your project root:
{
  "quality": 80,
  "maxWidth": 1920,
  "maxHeight": 1080,
  "convertToWebp": false,
  "folder": "./images",
  "skipExisting": true,
  "createBackup": true,
  "outputFolder": null
}
  1. Run the compression:
npm run compress-images

Configuration

Create an img.config.json file in your project root with the following options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | quality | Number | 80 | Output image quality (0-100) | | maxWidth | Number | 1920 | Maximum width of output images | | maxHeight | Number | 1080 | Maximum height of output images | | convertToWebp | Boolean | false | Convert images to WebP format | | folder | String | "./images" | Source folder containing images to process | | skipExisting | Boolean | true | Skip already processed images | | createBackup | Boolean | true | Create backup of original images | | outputFolder | String|null | null | Custom output directory (null to overwrite originals) |

Example Usage

Basic Compression

For basic image compression with default settings:

{
  "folder": "./images",
  "quality": 80
}

Convert to WebP

To compress and convert all images to WebP format:

{
  "folder": "./images",
  "quality": 85,
  "convertToWebp": true,
  "outputFolder": "./compressed"
}

High-Quality Resize

For resizing large images while maintaining high quality:

{
  "folder": "./images",
  "quality": 90,
  "maxWidth": 1920,
  "maxHeight": 1080,
  "createBackup": true
}

CLI Output

The tool provides detailed statistics after processing:

  • Number of images processed
  • Total size reduced (in MB)
  • Average compression percentage
  • Processing status for each image

Example output:

✔ Image compression completed!

Stats:
- Images processed: 24
- Total size reduced: 15.7 MB
- Average compression: 65.3%

Error Handling

  • The tool creates backups by default (can be disabled)
  • Failed image processing is reported but doesn't stop the batch
  • Invalid configuration files trigger helpful error messages
  • Missing source directory prompts for creation

Requirements

  • Node.js 12.0 or higher
  • NPM or Yarn package manager

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

Built with:

  • Sharp - High-performance image processing
  • Glob - File pattern matching
  • Chalk - Terminal string styling
  • Ora - Terminal spinner