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

universal-image-optimizer

v1.0.0-alpha.2

Published

A versatile, configuration-driven image optimization and transformation tool powered by sharp.

Downloads

108

Readme

Universal Image Optimizer

Universal Image Optimizer is a CLI tool for optimizing images with advanced features. It supports multiple image formats and provides fine-grained control over various image processing operations.


Features

  • Supports multiple image formats: JPEG, PNG
  • Offers advanced image processing features:
    • Quality
    • Grayscale conversion
    • Metadata stripping
    • Tinting
    • Blurring
    • Rotations, flips, and flops
    • Affine transformations
    • Image sharpening
    • Thresholding, convolution, and more
  • Highly configurable via a JavaScript configuration file
  • Easy-to-use CLI commands

Installation

Install the Universal Image Optimizer globally using npm:

npm install -g universal-image-optimizer

Usage

Universal Image Optimizer works with two primary commands:

1. Initialize Configuration File

To create a default configuration file in your project directory, run:

npx universal-image-optimizer init

This will generate a file named image-optimizer-config.js in your project directory with the following content:

Configuration File Structure

| Property | Type | Description | |------------------|--------------|-------------------------------------------------------------------------------------------------| | source | string | The directory containing the images to optimize. | | destination | string | The target directory where the optimized images will be saved. | | images | array | An array of objects defining image processing operations. | | type | string | The image format (e.g., jpeg, png). | | quality | number | The quality level for the optimized images. | | grayscale | boolean | Whether to apply a grayscale filter. | | stripMetadata | boolean | Whether to strip metadata from the images. | | tint | string | Apply a tint color in hexadecimal format (e.g., #FF0000). | | blur | number | Apply Gaussian blur with a specified sigma value. | | rotate | number | Rotate the image by the specified degrees (e.g., 90, 180). | | flip | boolean | Mirror the image vertically. | | flop | boolean | Mirror the image horizontally. | | affine | object | Perform affine transformation with matrix and optional options (e.g., background color). | | sharpen | object | Apply sharpening with options like sigma. | | median | number | Apply a median filter with a specified size. | | flatten | boolean | Flatten the image by merging alpha transparency with a background color. | | gamma | object | Apply gamma correction with options like gamma. | | negate | boolean | Produce the negative of the image. | | normalise | boolean | Enhance image contrast by stretching its luminance. | | clahe | object | Apply contrast-limited adaptive histogram equalization. | | convolve | object | Convolve the image with a specified kernel. | | threshold | number | Apply a pixel threshold. | | boolean | object | Perform bitwise operations with operand and operator. | | linear | object | Adjust image levels with linear transformations. | | recomb | array | Apply a recombination matrix (e.g., for sepia effects). | | modulate | object | Adjust brightness, saturation, hue, and lightness. |

Example Configuration File

export default {
  imageOptimize: [
    {
      source: 'src/images',
      destination: 'dist/images',
      images: [
        {
          type: 'jpeg',
          quality: 80,
          grayscale: true,
          stripMetadata: false,
          tint: '#FF0000',
          blur: 5,
          rotate: 90,
          flip: true,
          flop: false,
          affine: {
            matrix: [[1, 0], [0.3, 1]],
            options: { background: '#ffffff' }
          },
          sharpen: { sigma: 2 },
          median: 3,
          flatten: true,
          gamma: { gamma: 2.2 },
          negate: true,
          normalise: true,
          clahe: { width: 3, height: 3, maxSlope: 3 },
          convolve: {
            width: 3,
            height: 3,
            kernel: [-1, 0, 1, -2, 0, 2, -1, 0, 1]
          },
          threshold: 128,
          boolean: {
            operand: 'src/operand.png',
            operator: 'and'
          },
          linear: { a: 0.5, b: 2 },
          recomb: [
            [0.3588, 0.7044, 0.1368],
            [0.2990, 0.5870, 0.1140],
            [0.2392, 0.4696, 0.0912]
          ],
          modulate: {
            brightness: 1.2,
            saturation: 0.8,
            hue: 180,
            lightness: 10
          }
        }
      ]
    }
  ]
};

2. Optimize Images

After setting up the configuration file, run the following command to optimize your images:

npx universal-image-optimizer start

This will process images based on the configuration file and save them to the specified destination.


Logs and Messages

This tool uses color-coded messages for better clarity, powered by picocolors:

  • Success (Green): Indicates successful image optimizations.
  • Warnings (Yellow): Alerts you to potential issues, such as missing directories.
  • Errors (Red): Displays issues with configuration or file processing.

License

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


Created By

This project was developed by Kenan Gündoğan. Contributions and feedback are welcome!


Contribution

Contributions are welcome! If you have ideas or find bugs, feel free to open an issue or create a pull request on the GitHub repository.


Links