Skip to content

About

Batch convert and optimize images to JPEG format with automatic resizing, compression, and EXIF-based rotation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Image Optimizer

Batch convert and optimize images to JPEG format with automatic resizing, compression, and EXIF-based rotation.

Features

  • Supported Formats: .jpg, .jpeg, .png, .webp, .tif, .tiff, .bmp, .gif, .heic, .heif
  • Auto-Rotation: Rotates images based on EXIF data for correct orientation
  • Resizing: Optional width and height constraints with aspect ratio preservation
  • Compression: Configurable JPEG quality (0-100, default: 78) using mozjpeg
  • Background Flattening: Converts transparent PNGs with white background
  • Structure Preservation: Maintains directory structure in output
  • Dry-Run Mode: Preview optimization without writing files
  • Compression Reporting: Shows compression savings percentage

Prerequisites

  • Node.js 14.x or higher

Installation

cd img-opt
npm install

This installs the required sharp image processing library and dependencies.

Usage

node optimize-images.js [OPTIONS]

CLI Arguments

Argument Default Description
--in ./Original Input directory containing images to optimize
--out ./Optimized Output directory for optimized images
--quality 78 JPEG quality (0-100, lower = smaller file size)
--maxWidth 1800 Maximum image width in pixels (0 = no limit)
--maxHeight 0 Maximum image height in pixels (0 = no limit)
--overwrite false Overwrite existing files in output directory
--dryRun false Preview changes without writing files

Example Commands

Basic optimization with defaults:

node optimize-images.js

This optimizes images from ./Original to ./Optimized with quality 78 and max width 1800px.

Custom quality and dimensions:

node optimize-images.js --in "./input" --out "./output" --quality 85 --maxWidth 2400 --maxHeight 1600

Preview changes without writing:

node optimize-images.js --in "./input" --out "./output" --dryRun

Overwrite existing optimized files:

node optimize-images.js --in "./input" --out "./output" --overwrite

Output

The optimizer creates a new directory (specified by --out) containing:

  • Optimized JPEG files in the same directory structure as the input
  • All images converted to .jpg format
  • Reduced file sizes compared to originals
  • Compression statistics printed to console

Users place original images in the Original folder, and optimized results are saved to the Optimized folder.

Tips for Best Results

  • Quality Setting: Use 78-82 for web delivery, 85-90 for high-quality output
  • Dimensions: 1800px width is suitable for most web displays; reduce for mobile optimization
  • Testing: Use --dryRun first to preview results without committing changes
  • Backup: Keep original images; this tool only writes to the output directory

About

Batch convert and optimize images to JPEG format with automatic resizing, compression, and EXIF-based rotation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages