PHPackages                             dalpras/image-processor - 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. dalpras/image-processor

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

dalpras/image-processor
=======================

Unified image-processing library based on Imagick, offering stateless service + composable operations.

v1.1(3mo ago)00MITPHPPHP ^8.2

Since Jul 14Pushed 3mo agoCompare

[ Source](https://github.com/dalpras/image-processor)[ Packagist](https://packagist.org/packages/dalpras/image-processor)[ RSS](/packages/dalpras-image-processor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

image-processor
===============

[](#image-processor)

A modular, stateless image processing toolkit for PHP built on **Imagick**.
Compose powerful pipelines with simple, reusable operations for resizing, cropping, transforming, filtering, watermarking, and more.

---

✨ Features
----------

[](#-features)

- **Composable:** Chain any number of operations for advanced image workflows
- **Rich Operations:** Resize, crop, fit, filter, overlay, watermark, rotate, background, and more
- **Strict typing:** PHP 8.1+, PSR-4, Psalm/PHPStan ready
- **No /tmp clutter:** Uses dedicated temp folders for all operations
- **Modern API:** Pass closures or handler objects for complete flexibility
- **Robust:** Handles missing files, fallbacks, and generates placeholder images automatically

---

📦 Installation
--------------

[](#-installation)

```
composer require dalpras/image-processor
```

Or, add to your `composer.json`:

```
{
  "require": {
    "dalpras/image-processor": "^1.0"
  }
}
```

---

🚀 Quick Start
-------------

[](#-quick-start)

```
use DalPraS\Image\ImageProcessor;
use DalPraS\Image\Handlers\ImageResize;
use DalPraS\Image\Handlers\ImageCrop;
use DalPraS\Image\Handlers\ImageFit;
use DalPraS\Image\Handlers\ImageOverlay;
use DalPraS\Image\Handlers\ImageWatermark;
use DalPraS\Image\Handlers\ImageTransform;
use DalPraS\Image\Handlers\ImageFilter;

$processor = new ImageProcessor(__DIR__ . '/tmp');

// Compose a processing pipeline:
$operations = [
    ImageResize::resize(800, 600),
    ImageFit::fitToTarget(400, 300, 'fill'),
    ImageOverlay::overlay("Demo", 50, 50, null, 32, 'white', 0.7),
    ImageWatermark::watermark(__DIR__.'/logo.png', 'bottom-right', 0.3),
    ImageTransform::rotate(15),
    ImageFilter::filter('grayscale')
];

// Process the image:
$info = $processor->process(
    __DIR__ . '/input.jpg',
    [
        'outputDir'   => __DIR__ . '/out',
        'outputExt'   => 'webp',
        'operations'  => $operations,
        'fallback'    => __DIR__ . '/fallback.jpg',
    ]
);

echo $info->getWidth() . ' x ' . $info->getHeight();
echo $info->getInlinePng(); // Data URI for HTML
```

---

🛠️ Supported Operations
-----------------------

[](#️-supported-operations)

All operations return an `ImageHandle` for use in the `operations` pipeline.

### **Resize**

[](#resize)

- `resize(int $width, int $height, bool $keepAspect = true): ImageHandle`
- `resizeByRatio(int $dim, bool $isWidth = true): ImageHandle`

### **Fit/Fill**

[](#fitfill)

- `fitToTarget(int $targetWidth, int $targetHeight, string $mode = 'fit', string $anchor = 'center', string $background = 'white'): ImageHandle`
    - Modes: `fit`, `fitWidth`, `fitHeight`, `fill`

### **Crop &amp; Trim**

[](#crop--trim)

- `crop(int $width, int $height, int $x, int $y): ImageHandle`
- `trim(string $background = 'white'): ImageHandle`

### **Background**

[](#background)

- `backgroundColor(string $color): ImageHandle`
    - Sets the image background color (useful before flattening or composing).

### **Clip (Alpha Mask)**

[](#clip-alpha-mask)

- `clipPath(bool $inside = false): ImageHandle`
    - Uses 8BIM clipping path #1 for precise masking.

### **Overlay (Text)**

[](#overlay-text)

- `overlay(string $text, int $x, int $y, string $font = null, int $size = 20, string $color = 'black', ?float $opacity = null, int $angle = 0, int $align = Imagick::ALIGN_LEFT): ImageHandle`
    - Adds text overlay at specified coordinates with style options.

### **Transform**

[](#transform)

- `rotate(float $degrees): ImageHandle`
    - Rotates image by specified degrees.

### **Watermark**

[](#watermark)

- `watermark(string $path, string $position = 'center', ?float $opacity = null): ImageHandle`
    - Overlays an image as a watermark. Supports all corners and center.

### **Filter**

[](#filter)

- `filter(string $type, ...$args): ImageHandle`
    - Image filters supported:
        - `grayscale`
        - `sepia` (optionally with threshold)
        - `blur` (with radius &amp; sigma)
        - Extend with more as needed!

---

📋 API Reference
---------------

[](#-api-reference)

### ImageProcessor

[](#imageprocessor)

- `__construct(?string $tempDir = null)`
- `process(string $imagePath, array $options = []): ImageInfo`

#### Options

[](#options)

KeyTypeDefaultDescriptionoutputDirstringimage pathWhere to write the output imageoutputExtstring'webp'Output image extension/formatforceboolfalseOverwrite output if it existsoperationsarray\[\]List of `ImageHandle` operationsfallbackstringnullFallback image path if source is missing---

### ImageInfo

[](#imageinfo)

Returned from `process()`.
Extends `SplFileInfo`, with:

- `getWidth(): int`
- `getHeight(): int`
- `getRatio(): float`
- `getInlinePng(): string` — Data URI for HTML ``
- `getSpaceHolder(): string` — SVG placeholder (for lazy loading, etc.)

---

🐘 Symfony Integration Example
-----------------------------

[](#-symfony-integration-example)

```
# services.yaml
DalPraS\Image\ImageProcessor:
    arguments: ['%kernel.cache_dir%/imagick-tmp']
    public: true
```

---

🧪 Testing
---------

[](#-testing)

```
composer install
vendor/bin/phpunit
```

---

🤝 Contributions
---------------

[](#-contributions)

Contributions are welcome!
Open an issue or submit a pull request.

---

📄 License
---------

[](#-license)

MIT © Stefano Dal Prà

---

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance79

Regular maintenance activity

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

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

Every ~196 days

Total

2

Last Release

112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f4ad7c52ee1f0a8936e8bb6bcc95f15d4f55ce63233a0fa629da25bba024bd97?d=identicon)[dalpras](/maintainers/dalpras)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dalpras-image-processor/health.svg)

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

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

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