PHP code example of golchha21 / resmushit

1. Go to this page and download the library: Download golchha21/resmushit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

golchha21 / resmushit example snippets

 bash
php artisan vendor:publish --provider Golchha21\ReSmushIt\Providers\ServiceProvider --tag=config
 php
// config/ReSmushIt.php

return [

    // Keep a copy of the original image
    'original' => true,

    // Image quality (0–100)
    'quality' => 92,

    // Supported mime types
    'mime' => [
        'image/png',
        'image/jpeg',
        'image/gif',
        'image/bmp',
        'image/tiff',
    ],

    // Custom User-Agent for API requests
    'useragent' => 'ReSmushIt v1.3.4',

    // Preserve EXIF metadata
    'exif' => false,
    
    // Maximum allowed file size in bytes (e.g. 5 MB)
    'max_filesize' => 5242880,
];
 php
$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);
 php
$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);
 php
$result = Optimize::path($file);

if (isset($result['error'])) {
    // Handle the error (log it, retry, notify user, etc.)
}