PHPackages                             coderden/image-resizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. coderden/image-resizer

ActiveLibrary[Image &amp; Media](/categories/media)

coderden/image-resizer
======================

Professional PHP image resizing library with multiple driver support (GD, Imagick)

1.0.0(5mo ago)03MITPHPPHP ^8.1

Since Jan 16Pushed 5mo agoCompare

[ Source](https://github.com/dnsinyukov/image-resizer)[ Packagist](https://packagist.org/packages/coderden/image-resizer)[ RSS](/packages/coderden-image-resizer/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Image Resizer
=============

[](#image-resizer)

[![Latest Version](https://camo.githubusercontent.com/9eb663c2e075a1a80c105e18d85453e24659a807574e8e12c3de1d02adaab42f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f64657264656e2f696d6167652d726573697a65722e737667)](https://packagist.org/packages/coderden/image-resizer)[![PHP Version](https://camo.githubusercontent.com/e6fdeec0c747573d8d00baf70e94e392cb9959241ec2b9f02e082b3be59e5c0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f64657264656e2f696d6167652d726573697a65722e737667)](https://php.net)[![License](https://camo.githubusercontent.com/ab92b7f6cc930e1ff4a9c7fe1244e6e02b2862191ce088923f17af29b31a6f4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f64657264656e2f696d6167652d726573697a65722e737667)](https://packagist.org/packages/coderden/image-resizer)

Professional PHP image resizing library with multiple driver support. Supports GD and Imagick drivers with a unified API.

Features
--------

[](#features)

- **Multi-driver support**: Choose between GD and Imagick drivers
- **Fluent API**: Chainable methods for easy image manipulation
- **Multiple operations**: Resize, crop, rotate, watermark, aspect ratio adjustments
- **Format support**: JPEG, PNG, GIF, WebP
- **Extensible architecture**: Easy to add custom drivers
- **PHP 8.1+**: Modern PHP with type safety

Installation
------------

[](#installation)

```
composer require coderden/image-resizer
```

Quick Start
-----------

[](#quick-start)

```
$processor = new ImageProcessor('gd'); // or 'imagick'

// Load, resize, and save
$processor->load('input.jpg')
    ->resize(800, 600)
    ->save('output.jpg', 85);

// Get image as string
$imageData = $processor->load('photo.png')
    ->crop(300, 300)
    ->get('webp', 80);
```

Usage Examples
--------------

[](#usage-examples)

### Basic Resizing

[](#basic-resizing)

```
$processor = new ImageProcessor();

// Resize with width only (maintains aspect ratio)
$processor->load('image.jpg')
    ->resize(800)
    ->save('resized.jpg');

// Resize with height only
$processor->load('image.jpg')
    ->resize(null, 600)
    ->save('resized.jpg');

// Resize to exact dimensions (may distort)
$processor->load('image.jpg')
    ->resize(800, 600)
    ->save('resized.jpg');
```

### Cropping

[](#cropping)

```
// Crop to specific dimensions
$processor->load('image.jpg')
    ->crop(300, 200)
    ->save('cropped.jpg');

// Crop with custom position
$processor->load('image.jpg')
    ->crop(300, 200, 100, 50) // x=100, y=50
    ->save('cropped.jpg');
```

### Aspect Ratio

[](#aspect-ratio)

```
// Crop to 16:9 aspect ratio
$processor->load('image.jpg')
    ->aspectRatio(16/9)
    ->save('widescreen.jpg');

// Crop to square with top alignment
$processor->load('image.jpg')
    ->aspectRatio(1, 'top')
    ->save('square-top.jpg');

// Available positions: 'center', 'top', 'bottom', 'left', 'right'
```

### Rotation

[](#rotation)

```
// Rotate 45 degrees
$processor->load('image.jpg')
    ->rotate(45)
    ->save('rotated.jpg');

// Rotate -90 degrees (counter-clockwise)
$processor->load('image.jpg')
    ->rotate(-90)
    ->save('rotated.jpg');
```

### Watermark

[](#watermark)

```
// Add watermark
$processor->load('image.jpg')
    ->watermark('watermark.png', 'bottom-right', 50)
    ->save('watermarked.jpg');

// Available positions:
// 'top-left', 'top-right', 'bottom-left', 'bottom-right', 'center'
```

### Driver Selection

[](#driver-selection)

```
// Use GD driver (default)
$processor = new ImageProcessor('gd');

// Use Imagick driver (requires ext-imagick)
$processor = new ImageProcessor('imagick');

// Use specific driver for operation
$image = $processor->driver('imagick')
    ->load('image.tiff')
    ->resize(800, 600)
    ->get('jpg');
```

### Getting Image Data

[](#getting-image-data)

```
// Get as binary string
$jpegData = $processor->load('image.png')
    ->resize(800, 600)
    ->get('jpg', 85);

// Get image dimensions
$dimensions = $processor->load('image.jpg')
    ->getDimensions();
// Returns: ['width' => 1920, 'height' => 1080]
```

Static Helper Usage
-------------------

[](#static-helper-usage)

The package includes a static helper class `Resizer` for quick and easy image processing.

### Basic Static Usage

[](#basic-static-usage)

```
use CoderDen\ImageResizer\Resizer;

// Quick resize and save
Resizer::resize('input.jpg', 'output.jpg', 800, 600);

// Load and process with method chaining
Resizer::load('image.jpg')
    ->resize(300, 200)
    ->rotate(90)
    ->save('processed.jpg');

// Use different driver
Resizer::driver('imagick')
    ->load('image.tiff')
    ->save('output.jpg');
```

### Quick Helper Methods

[](#quick-helper-methods)

```
// Quick thumbnail creation
Resizer::thumbnail('photo.jpg', 'thumb.jpg', 150, true, 85);

// Quick crop
Resizer::crop('image.jpg', 'cropped.jpg', 300, 200);

// Get image dimensions
$size = Resizer::getImageSize('photo.jpg');
echo "Width: {$size['width']}, Height: {$size['height']}";

// Convert format
Resizer::convertFormat('input.png', 'output.webp', 'webp', 80);

// Base64 operations
$base64 = Resizer::toBase64('image.jpg', 800, 600);
Resizer::fromBase64($base64, 'output.jpg');
```

### Batch Processing

[](#batch-processing)

```
$images = [
    [
        'input' => 'image1.jpg',
        'output' => 'thumb1.jpg',
        'width' => 150,
        'height' => 150,
    ],
    [
        'input' => 'image2.jpg',
        'output' => 'thumb2.jpg',
        'width' => 200,
        'height' => 200,
    ],
];

$results = Resizer::batchProcess($images, function($processor, $image) {
    return $processor
        ->resize($image['width'], $image['height'])
        ->save($image['output'], 85);
});
```

### Driver Configuration

[](#driver-configuration)

```
// Set default driver
Resizer::setDefaultDriver('imagick');

// Use specific driver
Resizer::driver('gd')
    ->load('image.jpg')
    ->resize(800, 600);
```

Advanced Usage
--------------

[](#advanced-usage)

### Custom Driver

[](#custom-driver)

```
$processor = new ImageProcessor();

// Register custom driver
$processor->extend('custom', function () {
    return new class implements DriverInterface {
        // Implement all required methods
        public function load($source): self { /* ... */ }
        public function resize(?int $width = null, ?int $height = null): self { /* ... */ }
        // ... other methods
    };
});

// Use custom driver
$processor->driver('custom')
    ->load('image.jpg')
    ->resize(800, 600);
```

### Error Handling

[](#error-handling)

```
try {
    $processor = new ImageProcessor('imagick');
    $processor->load('nonexistent.jpg')
        ->resize(800, 600)
        ->save('output.jpg');
} catch (ImageDriverException $e) {
    // Driver-related errors (extension not loaded, etc.)
    echo "Driver error: " . $e->getMessage();
} catch (ImageProcessingException $e) {
    // Image processing errors
    echo "Processing error: " . $e->getMessage();
} catch (Exception $e) {
    // Other errors
    echo "Error: " . $e->getMessage();
}
```

API Reference
-------------

[](#api-reference)

### ImageProcessor Methods

[](#imageprocessor-methods)

- `driver(?string $driver = null): DriverInterface` - Get driver instance
- `getDefaultDriver(): string` - Get default driver name
- `extend(string $name, callable $callback): void` - Register custom driver

### Driver Methods

[](#driver-methods)

All methods return `$this` for chaining except where noted.

- `load(string|resource $source): self` - Load image from file or resource
- `resize(?int $width = null, ?int $height = null): self` - Resize image
- `crop(int $width, int $height, ?int $x = null, ?int $y = null): self` - Crop image
- `aspectRatio(float $ratio, string $position = 'center'): self` - Crop to aspect ratio
- `rotate(float $angle): self` - Rotate image
- `watermark(string $watermarkPath, string $position = 'bottom-right', int $opacity = 100): self` - Add watermark
- `save(string $path, int $quality = 90, ?string $format = null): bool` - Save to file
- `get(?string $format = null, int $quality = 90): string` - Get as binary string
- `getDimensions(): array` - Get image dimensions
- `destroy(): void` - Free resources

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- GD extension (required)
- Imagick extension (optional, for Imagick driver)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance70

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

167d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19547875?v=4)[Denis Sinyukov](/maintainers/dnsinyukov)[@dnsinyukov](https://github.com/dnsinyukov)

---

Top Contributors

[![dnsinyukov](https://avatars.githubusercontent.com/u/19547875?v=4)](https://github.com/dnsinyukov "dnsinyukov (1 commits)")

### Embed Badge

![Health badge](/badges/coderden-image-resizer/health.svg)

```
[![Health](https://phpackages.com/badges/coderden-image-resizer/health.svg)](https://phpackages.com/packages/coderden-image-resizer)
```

###  Alternatives

[char0n/ffmpeg-php

PHP wrapper for FFmpeg application

495240.6k1](/packages/char0n-ffmpeg-php)[goat1000/svggraph

Generates SVG graphs

135911.1k3](/packages/goat1000-svggraph)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

16653.6k2](/packages/gravatarphp-gravatar)[rsoury/wp-imgix

Rewrites WordPress image URLs to use ImgIX

167.2k](/packages/rsoury-wp-imgix)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
