PHP code example of daiyanmozumder / image-wizard

1. Go to this page and download the library: Download daiyanmozumder/image-wizard 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/ */

    

daiyanmozumder / image-wizard example snippets


return [
    'default_format' => 'webp', // Convert everything to webp by default

    'python' => [
        'executable' => env('IMAGE_WIZARD_PYTHON_EXECUTABLE', 'python3'),
        'timeout' => 60, // Maximum execution time in seconds
    ],

    'quality' => [
        'jpeg' => 80,
        'webp' => 80,
        'avif' => 50,
    ],

    'variants' => [
        'thumbnail' => ['width' => 150, 'height' => 150, 'fit' => 'crop'],
        'medium'    => ['width' => 800, 'height' => 800, 'fit' => 'contain'],
        'large'     => ['width' => 1200, 'height' => 1200, 'fit' => 'contain'],
    ],
];

use ImageWizard;

ImageWizard::load('public/uploads/raw.jpg')
    ->resize(800, 600, 'cover')
    ->format('webp')
    ->quality(85)
    ->save('public/images/optimized.webp');

ImageWizard::load('image.jpg')
    ->resize(500, 500, 'contain') // (Default) Scale to fit within bounds
    // ->resize(500, 500, 'cover')   // Scale to fill bounds exactly, cropping overflow
    // ->resize(500, 500, 'stretch') // Ignore aspect ratio, force to exact dimensions
    // ->resize(500, 500, 'pad')     // Fit within bounds, adding transparent/white padding
    ->save('output.jpg');

ImageWizard::load('photo.jpg')
    ->watermark('logo.png', [
        'position'   => 'bottom-right', // CSS-like positioning: top-left, center, bottom-right, etc.
        'opacity'    => 0.6,            // 60% opacity (0.0 to 1.0)
        'size_ratio' => 0.12,           // Auto-scales watermark to 12% of main image's smaller dimension (default: 0.12)
        'margin'     => 20,             // Explicit margin offset in px (auto-calculated as 3% min 10px if omitted)
    ])
    ->save('photo-watermarked.jpg');

ImageWizard::fromDisk('s3', 'raw-uploads/user.jpg')
    ->resize(1200)
    ->watermark('watermark.png')
    ->toDisk('s3', 'optimized/user.jpg');

// Instantly returns a response to the user
ImageWizard::load('massive-raw-file.tiff')
    ->format('avif')
    ->resize(2000)
    ->queue('public/optimized.avif');

ImageWizard::load('hero.png')
    ->generateVariants('public/hero.jpg', ['thumbnail', 'medium', 'large']);

$files = ['img1.jpg', 'img2.png', 'img3.webp'];

ImageWizard::resize(500, 500, 'crop')
    ->format('webp')
    ->batch($files, 'public/batch-output/');

ImageWizard::load('photo.jpg')
    ->preserveMetadata()
    ->save('photo-preserved.jpg');
bash
php artisan vendor:publish --tag=image-wizard-config
bash
   php artisan config:clear