A powerful and easy-to-use PHP library for image processing using the GD extension. Transform, compress, watermark, and optimize images with just a few lines of code.
- 🖼️ Image Resizing - Maintain aspect ratios automatically
- 🗜️ Smart Compression - Compress to target file sizes
- 🏷️ Watermarking - 9 preset positions with diagonal-based scaling
- 🎨 Opacity Control - Add transparency to images
- 🚀 WebP Conversion - Modern format with superior compression
- ⚡ Combined Operations - Efficient multi-step workflows
- PHP 8.1 or higher
- GD extension (usually included with PHP)
ext-imagickversion 3.7 or higher
Install via Composer:
composer require kenura/imagick<?php
require_once __DIR__ . '/vendor/autoload.php';
use Kenura\Imagick\ImageProcessor;
$processor = new ImageProcessor();
// Resize an image
$processor->resizeImage('input.jpg', 'output.jpg', 800, 600);
// Compress to ~100KB
$processor->compressToJpg('large.jpg', 'compressed.jpg', 100);
// Add watermark
$processor->addWatermark('photo.jpg', 'watermarked.jpg', 'logo.png', 'bottom-right', 10);
// Convert to WebP
$processor->convertToWebP('photo.jpg', 'photo.webp', 85);Resize images while maintaining aspect ratio.
$processor->resizeImage($inputPath, $outputPath, $width, $height);Compress images to a target file size.
$processor->compressToJpg($inputPath, $outputPath, $targetSizeKB, $quality = 80);Add watermarks with flexible positioning.
$processor->addWatermark($inputPath, $outputPath, $watermarkPath, $position = 'center', $scale = 10);Positions: center, top, bottom, left, right, top-left, top-right, bottom-left, bottom-right
Adjust image transparency (output as PNG).
$processor->addOpacity($inputPath, $outputPath, $opacityPercent);Convert images to modern WebP format.
$processor->convertToWebP($inputPath, $outputPath, $quality = 80);Resize and compress in one step.
$processor->resizeAndCompress($inputPath, $outputPath, $width, $height, $targetSizeKB);Complete processing pipeline.
$processor->resizeWatermarkAndCompress(
$inputPath,
$outputPath,
$width,
$height,
$watermarkPath,
$position,
$scale,
$scale,
$targetSizeKB
);This library includes both manual example scripts and automated tests.
Run example scripts to see the library in action:
# Resize example
php test/resize.php
# Compression example
php test/compress.php
# Watermark example
php test/watermark.php
# WebP conversion example
php test/webp.php
# Opacity example
php test/opacity.phpRun the full PHPUnit test suite:
# Install dev dependencies
composer install
# Run tests
composer test
# Run tests with coverage
composer test:coverageThe automated tests run on every push via GitHub Actions, testing across PHP 7.4, 8.0, 8.1, 8.2, and 8.3.
For detailed guides and API reference, visit the full documentation.
- Installation Guide
- Quick Start
- Resizing Images
- Compressing Images
- Adding Watermarks
- WebP Conversion
- API Reference
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Kenura R. Gunarathna
- Email: kenuragunarathna@gmail.com
- GitHub: @Kenura-R-Gunarathna
Thanks to everyone using this library! Your feedback and contributions help make it better.