PHP code example of rikodev / laravel-imgproxy

1. Go to this page and download the library: Download rikodev/laravel-imgproxy 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/ */

    

rikodev / laravel-imgproxy example snippets


use RikoDEV\LaravelImgproxy\Options;
use RikoDEV\LaravelImgproxy\Enums\ResizeType;
use RikoDEV\LaravelImgproxy\Enums\Gravity;
use RikoDEV\LaravelImgproxy\Enums\Format;

imgproxy($url, new Options(...))

use RikoDEV\LaravelImgproxy\Facades\Imgproxy;

Imgproxy::url($url, new Options(...))

use RikoDEV\LaravelImgproxy\ImgproxyManager;

class MyService
{
    public function __construct(private readonly ImgproxyManager $imgproxy) {}

    public function thumbnail(string $url): string
    {
        return $this->imgproxy->url($url, new Options(width: 400, height: 300));
    }
}

new Options(
    width:      ?int,        // Output width in pixels
    height:     ?int,        // Output height in pixels
    resize:     ResizeType,  // Resize algorithm (default: ResizeType::Fit)
    gravity:    ?Gravity,    // Crop gravity / focus point
    quality:    ?int,        // Output quality 1–100 (JPEG / WebP)
    enlarge:    bool,        // Allow enlarging beyond original size (default: false)
    format:     ?Format,     // Convert to this format (also sets the file extension)
    blur:       ?float,      // Gaussian blur sigma 0.3–1000
    brightness: ?int,        // Brightness adjustment -255–255
    contrast:   ?float,      // Contrast multiplier
    saturation: ?float,      // Saturation multiplier
)

imgproxy($url, new Options(width: 1200))

imgproxy($url, new Options(
    width:   600,
    height:  400,
    resize:  ResizeType::Fill,
    gravity: Gravity::Smart,
))

imgproxy($url, new Options(
    width:  128,
    height: 128,
    resize: ResizeType::Fill,
    format: Format::WebP,
))

imgproxy($url, new Options(
    width:   1920,
    height:  1080,
    resize:  ResizeType::Fill,
    gravity: Gravity::Smart,
    quality: 90,
    format:  Format::Avif,
))

imgproxy($url, new Options(width: 800, quality: 75))

imgproxy($url, new Options(width: 40, height: 40, blur: 10.0))

$opts = new Options(width: 600, height: 400, resize: ResizeType::Fill);

echo $opts->value;   // "rs:fill:600:400:0"
echo (string) $opts; // "rs:fill:600:400:0"

imgproxy($url, 'w:1200')
imgproxy($url, 's:32:32', 'webp')
imgproxy($url, 'w:600/h:176/rt:fill')
imgproxy($url, 'q:80', Format::WebP)  // Format enum also accepted for $ext
bash
php artisan vendor:publish --tag=imgproxy-config