DEV Community

Ulhas Vardhan Golchha
Ulhas Vardhan Golchha

Posted on • Originally published at Medium

reSmushit for Laravel

reSmush.it is a FREE API that provides image optimization. reSmush.it has been implemented on the most common CMS.

Moreover, reSmush.it is the most used image optimization API with more than 7 billions images already treated, and is still totally Free of charge !

Ever since I came to know about it I have been using the service for my WordPress setups.

When I started working with Laravel I was missing this service. So here is the package that I published and now am using in all my Laravel Projects.

Here is how you can use the package:

Install via Composer

composer require golchha21/resmushit
Enter fullscreen mode Exit fullscreen mode

Publish configuration file

php artisan vendor:publish --provider Golchha21\ReSmushIt\Providers\ServiceProvider --tag=config
Enter fullscreen mode Exit fullscreen mode

Once you publish the configuration file you can change the values as per you usage:

return [
    'original' => true|false,
    'quality' => 92,
    'mime' => [
        'image/png',
        'image/jpeg',
        'image/gif',
        'image/bmp',
        'image/tiff',
    ],
    'useragent' => 'SOME USER AGENT',
    'exif' => true|false,
];
Enter fullscreen mode Exit fullscreen mode

Finally, you can use it in two ways:

$file = public_path('images/news1.jpg');
$files = [
    public_path('images/news1.jpg'),
    public_path('images/news2.jpg'),
    public_path('images/news3.jpg'),
    public_path('images/news4.jpg'),
];
$resmushit = new ReSmushIt();
$result = $resmushit->path($file);
$results = $resmushit->paths($files);
Enter fullscreen mode Exit fullscreen mode

2.

$file = public_path('images/news1.jpg');
$files = [
    public_path('images/news1.jpg'),
    public_path('images/news2.jpg'),
    public_path('images/news3.jpg'),
    public_path('images/news4.jpg'),
];
Optimize::path($file);
Optimize::paths($files);

Enter fullscreen mode Exit fullscreen mode

Voila.

Do try and let me know. Also if you find any error and or bugs do add an issue here.

Few links:

Website | Github
reSmushIt for Laravel

Top comments (0)