PHP code example of imsus / laravel-imgproxy

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

    

imsus / laravel-imgproxy example snippets


'instances' => [
    'default' => [
        'url' => env('IMGPROXY_URL'),
        'key' => env('IMGPROXY_KEY'),
        'salt' => env('IMGPROXY_SALT'),
        'signature_size' => null,
        'encoding' => 'base64',
    ],

    'staging' => [
        'url' => 'https://imgproxy-staging.example.com',
        'key' => '...',
        'salt' => '...',
        'signature_size' => 16, // match IMGPROXY_SIGNATURE_SIZE on the server
        'encoding' => 'base64',
    ],
],

use Imsus\LaravelImgproxy\Imgproxy;

$url = Imgproxy::image('https://example.com/image.jpg')
    ->cover(300, 300)
    ->quality(80)
    ->toWebp()
    ->url();

// https://imgproxy.example.com/unsafe/rs:fill:300:300/q:80/f:webp/aHR0cHM6Ly9leGFtcGxlLmNvbS9pbWFnZS5qcGc

$base = Imgproxy::image('https://example.com/image.jpg')->quality(80);

$small = $base->width(320)->url();
$large = $base->width(1280)->url(); // quality:80 still applies; no width leak from $small

// https://imgproxy.example.com/7Fu-sZuoCXRc1LXWhM687mlhsd2SFxXBpiFjJk6vakw/rs:fill:300:300/...

use Illuminate\Support\Facades\Storage;

// Public disk -> url()
Storage::disk('public')->imgproxy('images/photo.jpg')
    ->width(800)
    ->toWebp()
    ->url();

// Private disk (S3) -> pre-signed temporaryUrl(), 5 minutes by default
Storage::disk('s3')->imgproxy('products/image.jpg', 3600)
    ->fit(800, 600)
    ->url();

Imgproxy::fromStorage('images/photo.jpg', 'public')->width(800)->url();
Imgproxy::fromStorage('products/image.jpg', 's3')->fit(800, 600)->url(); // pre-signed, 5 minutes by default

imgproxy()->image('unused')->disk('s3', 'products/image.jpg', 3600)->width(800)->url();

$image = imgproxy()->image('https://example.com/photo.jpg')
    ->width(800)
    ->toWebp()
    ->storePublicly('s3', 'processed/photo.webp');

$image->disk();      // 's3'
$image->path();      // 'processed/photo.webp'
$image->url();       // public disk -> https://.../processed/photo.webp
$image->url(3600);   // private disk -> pre-signed temporaryUrl(), 1 hour
$image->adapter();   // the destination disk adapter
bash
php artisan vendor:publish --tag="laravel-imgproxy-config"
bash
php artisan vendor:publish --tag="laravel-imgproxy"
bash
php artisan imgproxy:health          # default instance
php artisan imgproxy:health --instance=staging