grupobahez/imageoptimizer is a Laravel package for package for image optimization in laravel.
It currently has 0 GitHub stars and 0 downloads on Packagist (latest version v1.1.0).
Install it with composer require grupobahez/imageoptimizer.
Discover more Laravel packages by grupobahez
or browse all Laravel packages to compare alternatives.
Last updated
Package for optimizing and generating multiple image sizes in Laravel using Intervention Image.
composer require grupobahez/imageoptimizer
Publish the configuration file (optional):
php artisan vendor:publish --provider="Grupobahez\Imageoptimizer\ImageOptimizerServiceProvider"
Configure the values in config/imageoptimizer.php.
In your code, use the ImageOptimizer facade to optimize images:
use Grupobahez\Imageoptimizer\Facades\ImageOptimizer;
use Grupobahez\Imageoptimizer\Support\ResizeStrategies;
// ...
ImageOptimizer::optimize(Storage::disk('public')->path('myimage.jpg'), [
'disk' => 'public',
'quality' => 70,
'format' => 'webp',
'thumbnails' => [
'small' => [150, 150],
'medium' => [300, 300],
// ...
],
'strategy' => ResizeStrategies::COVER, // fill | crop | fit | cover | cover-top | cover-bottom | cover-left | cover-right
// cover-top-left | cover-top-right | cover-bottom-left | cover-bottom-right
'output_folder' => 'new-folder', // Optional: Specify a custom output folder
'output_file' => 'custom-name', // Optional: Specify a custom base filename
]);
Optimize images from url
use Grupobahez\Imageoptimizer\Facades\ImageOptimizer;
use Grupobahez\Imageoptimizer\Support\ResizeStrategies;
// ...
ImageOptimizer::optimizeFromUrl('https://example.com/image.jpg', [
'disk' => 'public',
'quality' => 70,
'format' => 'webp',
'thumbnails' => [
'small' => [150, 150],
'medium' => [300, 300],
// ...
],
'strategy' => ResizeStrategies::COVER, // fill | crop | fit | cover
'output_folder' => 'new-folder', // Optional: Specify a custom output folder
'output_file' => 'custom-name', // Optional: Specify a custom base filename
]);
The package includes a configuration file that you can overwrite by publishing it in your project. The default values are:
return [
'quality' => 80,
'format' => 'webp',
'strategy' => 'fit',
'thumbnails' => [
'small' => [150, 150],
'medium' => [300, 300],
'large' => [1024, 768],
],
];

fit: Maintains the aspect ratio; can handle 0 in width or height for proportional resizing.fill: Ensures the image covers the frame entirely, maintains the full image; can handle 0 in width or height.cover: Ensures the image covers the frame entirely, recropping from the center; can handle 0 in width or height.crop: Crops the image to exact dimensions; both width and height must be specified (does not support 0).cover-top: Ensures the image covers the frame entirely, recropping from the top; can handle 0 in width or height.cover-bottom: Ensures the image covers the frame entirely, recropping from the bottom; can handle 0 in width or height.cover-left: Ensures the image covers the frame entirely, recropping from the left; can handle 0 in width or height.cover-right: Ensures the image covers the frame entirely, recropping from the right; can handle 0 in width or height.cover-top-left: Ensures the image covers the frame entirely, recropping from the top-left; can handle 0 in width or height.cover-top-right: Ensures the image covers the frame entirely, recropping from the top-right; can handle 0 in width or height.cover-bottom-left: Ensures the image covers the frame entirely, recropping from the bottom-left; can handle 0 in width or height.cover-bottom-right: Ensures the image covers the frame entirely, recropping from the bottom-right; can handle 0 in width or height.output_folder option.output_file option.output_folder is not provided, the folder of the original image will be used.output_file is not provided, the name of the original image will be used as the base.The package includes unit tests with PHPUnit. You can run them using:
vendor/bin/phpunit
This package is licensed under the MIT License.