euginepj / laravel-image-resizer
Interactive image cropper and multi-format (WebP, JPEG, PNG, AVIF) converter package for Laravel.
Requires
- php: ^8.2
- illuminate/contracts: ^10.21|^11.0|^12.0
- illuminate/filesystem: ^10.21|^11.0|^12.0
- illuminate/http: ^10.21|^11.0|^12.0
- illuminate/routing: ^10.21|^11.0|^12.0
- illuminate/support: ^10.21|^11.0|^12.0
- illuminate/view: ^10.21|^11.0|^12.0
- intervention/image: ^3.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Interactive image cropping, resizing and multi-format conversion (WebP, JPEG, PNG, AVIF) for Laravel, powered by Intervention Image v3 and Alpine.js + Cropper.js.
The browser sends crop coordinates; the server crops the original file, so quality is never degraded by a canvas re-encode.
Requirements
- PHP 8.2+ with the GD (with WebP/AVIF support as needed) or Imagick extension
- Laravel 10, 11 or 12
- Alpine.js v3 loaded on the page (the component does not bundle it)
php artisan storage:linkwhen using thepublicdisk
Installation
composer require euginepj/laravel-image-resizer php artisan vendor:publish --tag=image-resizer-config # optional php artisan vendor:publish --tag=image-resizer-views # optional
Blade component
<x-image-resizer::cropper name="avatar" :aspect-ratio="1" :target-width="400" :target-height="400" :formats="['webp', 'jpg', 'png']" folder="avatars" /> <div x-data="{ urls: null }" @image-cropped.window="urls = $event.detail.urls"> <template x-if="urls"> <picture> <source :srcset="urls.webp" type="image/webp"> <img :src="urls.jpg" alt="Avatar"> </picture> </template> </div>
The image-cropped event detail contains name, paths, urls and base.
Component props: name, aspect-ratio, target-width, target-height, formats, folder, upload-url, button-label, modal-title.
Programmatic usage
use Euginepj\ImageResizer\Facades\ImageResizer; $paths = ImageResizer::load($request->file('photo')) ->rotate(90) ->crop(width: 500, height: 500, offsetX: 100, offsetY: 50) ->resize(300, 300) ->saveMultiFormat('uploads/avatars/user-123', ['webp', 'jpg', 'png']); ImageResizer::delete($paths);
Security
The built-in endpoint POST /image-resizer/upload is throttled (30/min) but not authenticated by default. Restrict it in config/image-resizer.php:
'routes' => ['enabled' => true, 'prefix' => 'image-resizer', 'middleware' => ['web', 'auth', 'throttle:30,1']],
Set 'enabled' => false to disable the route entirely and use the facade from your own controller.
Uploads are limited by max_upload_kb and max_pixels; folder accepts only letters, digits, -, _ and /.
Configuration
See config/image-resizer.php: driver, quality per format, default formats, disk, upload path, limits, routes and asset URLs (use your own files instead of the CDN).
Testing
composer install
composer test
License
MIT