laravel-enso / imagetransformer
Image transformer dependency for Laravel Enso
Requires
- php: ^8.0
- intervention/image-laravel: ^1.5
- laravel-enso/helpers: ^12.0
- spatie/laravel-image-optimizer: ^1.6
- dev-master
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.6.7
- 1.6.6
- 1.6.5
- 1.6.4
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.7
- 1.4.6
- 1.4.5
- 1.4.4
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- dev-hotfix/intervention-image
- dev-update/removeLaravelDependecy
- dev-upgrade/enso6-dr
- dev-upgrade/enso6
- dev-upgrade/laravel8
- dev-fixes/stylci
This package is auto-updated.
Last update: 2026-04-21 15:25:45 UTC
README
Description
Image Transformer provides a small service for validating, resizing, and optimizing uploaded images.
It wraps Intervention Image for resize operations and Spatie's image optimizer for post-processing, while enforcing a limited set of supported image mime types before any transformation is attempted.
The package is useful in upload flows where images should be normalized before storage, for example avatars, covers, gallery images, or document attachments that need size limits and optimization.
Installation
Install the package:
composer require laravel-enso/image-transformer
The package relies on:
intervention/image-laravelfor reading and resizing imagesspatie/laravel-image-optimizerfor optimization
To use resizing, the runtime must have at least one supported image extension installed:
gdimagick
Features
- Validates uploaded files before transformation.
- Supports
png,jpeg,gif, andwebpimages. - Optimizes images in place through Spatie's optimizer chain.
- Resizes images proportionally by width, by height, or by both through
resize(). - Prevents upsizing by only resizing when the original image is larger than the requested dimension.
- Saves transformations back to the original file path.
Usage
Create a transformer from an uploaded file:
use LaravelEnso\ImageTransformer\Services\ImageTransformer; $transformer = new ImageTransformer($file);
Optimize the original file:
$transformer->optimize();
Resize proportionally to a maximum width:
$transformer->width(512);
Resize proportionally to a maximum height:
$transformer->height(512);
Apply both constraints in sequence:
$transformer->resize(1024, 768);
::: tip Tip The transformer edits the original file in place.
If you need to preserve the original upload, copy or move it before calling optimize(), width(), height(), or resize().
:::
API
Service
LaravelEnso\ImageTransformer\Services\ImageTransformer
Constructor:
__construct(File $file)
Public methods:
optimize(): selfresize(int $width, int $height): selfwidth(int $width): selfheight(int $height): self
Supported Mime Types
The service accepts:
image/pngimage/jpegimage/gifimage/webp
Exceptions
The package exposes:
LaravelEnso\ImageTransformer\Exceptions\FileLaravelEnso\ImageTransformer\Exceptions\Dependency
Scenarios covered:
- invalid uploaded file
- unsupported mime type
- missing
gd/imagickextension when resizing
Depends On
Required Enso packages:
External dependencies:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!