PHP code example of uiarts / proxy-image

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

    

uiarts / proxy-image example snippets


\UIArts\ProxyImage\Facades\ProxyImage::pictureData(
    pictures: 'uploads/image.jpg',
    sizes: [
        'mobile' => [300, 'a'],
        'tablet' => [300, 'a'],
        'desktop' => [800, 'a'],
    ],
    attributes: [
        'mode' => 'fit',
        'quality' => 85,
        'densities' => [1, 2],
        'formats' => ['avif', 'jpg'],
        'alt' => 'Some alt',
        'lazyStrategy' => 'observer',
    ],
);

[
    'mode' => 'proxy', // proxy|bypass|placeholder
    'img' => [
        'src' => '/i/...',
        'srcset' => '/i/... 1x, /i/... 2x',
        'alt' => 'Some alt',
        'title' => 'Some title',
        'width' => 800,
        'height' => 'auto',
    ],
    'sources' => [
        [
            'type' => 'image/avif',
            'media' => '(min-width: 1200px)',
            'srcset' => '/i/... 1x, /i/... 2x',
        ],
    ],
]
bash
php artisan vendor:publish --tag=proxy-image-config
bash
php artisan vendor:publish --tag=proxy-image-public

public/images.php
nginx
location ^~ /i/ {
    9000;

    fastcgi_param SCRIPT_FILENAME $document_root/images.php;
    fastcgi_param SCRIPT_NAME /images.php;
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
    add_header X-Images-Entrypoint 1 always;
}

if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}