Skip to content

Node.js application designed to efficiently compress images using the Sharp library.

Notifications You must be signed in to change notification settings

astik-dev/sharp-image-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sharp logo sharp-image-compressor

sharp-image-compressor is a Node.js application designed to efficiently compress images using the Sharp library. This application provides a simple yet powerful way to compress various image formats including JPEG, PNG, WebP, AVIF, and TIFF. With sharp-image-compressor, you can quickly reduce the file size of your images without sacrificing quality.

Features

  • Supports multiple input and output formats: JPEG, PNG, WebP, AVIF, and TIFF.
  • Recognizes already compressed images, avoiding re-compression.
  • Configurable compression settings for each supported format.
  • Simple configuration via the config.js file.

Installation

To get started with Sharp Image Compressor, follow these steps:

  1. Clone this repository to your local machine:

    git clone https://github.com/astik-dev/sharp-image-compressor.git
  2. Navigate to the project directory:

    cd sharp-image-compressor
  3. Install dependencies using npm:

    npm install

Configuration

sharp-image-compressor behavior can be customized using the config.js file. Here's how you can tailor the configuration to suit your needs:

// Folder containing original images
export const originalsFolder = "./images/originals/";
// Folder for compressed images
export const compressedFolder = "./images/compressed/";

// Extensions of original images that will be compressed
export const extensionsToCompression = ["jpg", "jpeg", "png"];
// Formats to which original images will be compressed
export const compressionToFormats = ["jpeg", "webp"];

// Compression options for different formats
// These options can be configured based on Sharp documentation for each format:
// https://sharp.pixelplumbing.com/api-output
export const compressionOptions = {
    jpeg: {
        quality: 80,
        progressive: true,
        mozjpeg: true,
    },
    png: {
        quality: 80,
    },
    tiff: {
        quality: 80,
    },
    webp: {
        quality: 70,
    },
    avif: {
        quality: 70,
    }
}

Adjust the paths, extensions, formats, and compression options according to your requirements.

Usage

Once configured, you can start compressing images using the following command:

npm start

Requirements

  • Node.js
  • npm (Node Package Manager)

Resources

  • Sharp Documentation: Refer to Sharp's official documentation for detailed information on compression options and API usage.

About

Node.js application designed to efficiently compress images using the Sharp library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published