microweber-packages / microweber-image-optimization
Standalone Laravel package for image optimization: WebP conversion, lazy loading, responsive images, and cache management. Reusable in any Laravel app.
Package info
github.com/microweber-packages/microweber-image-optimization
pkg:composer/microweber-packages/microweber-image-optimization
Requires
- php: ^8.1
- illuminate/filesystem: ^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/routing: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
- intervention/image: ^3.0
- microweber-packages/microweber-package: *
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- filament/filament: ~5.0
- larastan/larastan: ^3.9
- laravel/dusk: ^8.0|^9.0
- livewire/livewire: ^3.0|^4.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
Suggests
- filament/filament: Required for the Filament admin settings page
- microweber-packages/media-pixum: For placeholder images
- microweber-packages/media-thumbnail: For media thumbnail URL generation
- microweber-packages/thumbnailer: For thumbnail resizing integration
Provides
None
Conflicts
None
Replaces
- microweber-packages/image-optimization: *
This package is auto-updated.
Last update: 2026-11-03 17:06:53 UTC
README
Standalone Laravel package for image optimization: WebP conversion, lazy loading HTML, responsive srcset generation, and WebP cache management.
Works in Microweber CMS and in any standalone Laravel application.
Requirements
- PHP 8.1+
- Laravel 10 / 11 / 12
- GD with WebP support or Imagick
intervention/image^3.0
Installation
composer require microweber-packages/microweber-image-optimization
The service provider is auto-discovered. Publish the config if needed:
php artisan vendor:publish --tag=image-optimization-config
Usage
use MicroweberPackages\ImageOptimization\Services\ImageOptimizationService; $service = app(ImageOptimizationService::class); // WebP conversion $result = $service->convertToWebp('/path/to/photo.jpg', ['quality' => 85]); $url = $service->getWebpOrOriginal('/path/to/photo.jpg'); // Optimized URL (optional resize + WebP) $url = $service->getOptimizedUrl('/images/photo.jpg', 800, 600); // Lazy / responsive HTML echo $service->generateLazyImage('/images/photo.jpg', 'Alt text'); echo $service->generateResponsiveImage('/images/photo.jpg', [320 => 320, 640 => 640], 'Alt');
Helper functions
optimized_image_url($src, $width = null, $height = null, $allowWebp = true); webp_image($src); lazy_image($src, $alt = null, $attributes = []); responsive_image($src, $sizes, $alt = null, $attributes = []); webp_supported(); webp_enabled(); lazy_loading_enabled(); client_supports_webp(); clear_webp_cache(); image_optimization_stats();
Blade directives
@optimizedImage($src, $width, $height) @webpImage($src) @lazyImage($src, $alt, $attributes) @responsiveImage($src, $sizes, $alt, $attributes) @webpPicture($src, $alt, $attributes) @lazyCss @lazyJs
Routes
| Method | URI | Name |
|---|---|---|
| GET | /image-optimization/webp |
image-optimization.webp |
| GET | /image-optimization/stats |
image-optimization.stats |
| POST | /image-optimization/clear-cache |
image-optimization.clear-cache |
| GET | /api/image-optimization/convert |
image-optimization.convert |
Filament admin
Register the plugin on your panel:
use MicroweberPackages\ImageOptimization\Filament\ImageOptimizationPlugin; $panel->plugin(ImageOptimizationPlugin::make());
Multi-database
The package is filesystem-oriented. Settings may optionally use Microweber get_option / save_option when available. Tests cover SQLite, MySQL, and PostgreSQL for package bootstrapping.
License
MIT