lakshanjs / jpegmini-sdk
A PHP SDK wrapper for the JPEGmini CLI image optimizer.
Requires
- php: >=7.4
This package is auto-updated.
Last update: 2025-05-30 09:57:14 UTC
README
A lightweight, production-ready PHP SDK wrapper for the JPEGmini Server CLI. It allows you to optimize JPEG images via command line directly from PHP, with support for resizing, quality settings, metadata removal, and more.
π¦ Installation
Install using Composer:
composer require lakshanjs/jpegmini-sdk
π Quick Start
use LakshanJS\Jpegmini\JpegminiSDK; $jpegmini = new JpegminiSDK('/usr/local/bin/jpegmini'); $result = $jpegmini->optimize('/path/to/input.jpg', [ 'output' => '/path/to/output.jpg', 'resize' => '60', 'quality_mode' => 1, 'remove_metadata' => true, 'skip_high_compression' => false ]); print_r($result);
βοΈ Options
Option | Type | Description |
---|---|---|
output |
string |
File or folder path where the optimized image(s) should be saved. If omitted, JPEGmini saves to the same folder as the input, appending _mini to the filename. |
recursive |
bool |
When optimizing a folder, determines whether subdirectories should be processed. Default: true |
logfile |
string |
Path to save JPEGmini logs (same as CLI -logfile ) |
log_level |
int |
CLI log verbosity: 0 (none), 1 (basic), 2 (verbose). Default: 1 |
csvfile |
string |
Path to save CSV summary of optimization results |
resize |
string |
Resize before optimization. Format: '50' (percentage) or '800x600' (fixed size) |
quality_mode |
int |
Output quality: 0 (best), 1 (high), 2 (medium). Default: 0 |
skip_high_compression |
bool |
Skips images already heavily compressed. Default: true |
remove_metadata |
bool |
Removes EXIF and other metadata from JPEG files. Default: false |
π Examples
β Optimize and Save with New Name
$jpegmini->optimize('/images/photo.jpg', [ 'output' => '/images/photo_compressed.jpg', ]);
π Overwrite Original File (β οΈ Destructive)
$jpegmini->optimize('/images/photo.jpg', [ 'output' => '/images/photo.jpg' ]);
π§© Resize & Remove Metadata
$jpegmini->optimize('/images/original.jpg', [ 'resize' => '800x600', 'remove_metadata' => true ]);
π Optimize Entire Folder (Recursively)
$jpegmini->optimize('/images/uploads', [ 'recursive' => true ]);
β Requirements
- PHP 7.4 or higher
- JPEGmini Server installed and accessible via CLI
- Executable binary path (e.g.
/usr/local/bin/jpegmini
)
π License
MIT License β free for commercial and personal use.
πββοΈ Author
Lakshan Jayasinghe
GitHub @lakshanjs
π¬ Contributing
Pull requests and suggestions are welcome! If you want to add Laravel integration, batch queue support, or auto-backup before overwrite, feel free to fork or raise an issue.
π‘ Tip
This SDK doesnβt use any HTTP calls or external services β it's a direct wrapper around the JPEGmini CLI. Itβs ideal for secure, offline image processing systems.