PHP code example of nicklog / imgproxy

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

    

nicklog / imgproxy example snippets


use NickLog\ImgProxy\ImgProxy;
use NickLog\ImgProxy\Signer\KeyPair;
use NickLog\ImgProxy\Options\Dpr;
use NickLog\ImgProxy\Options\Quality;
use NickLog\ImgProxy\Options\Width;
use NickLog\ImgProxy\Options\Height;

$imgProxyBaseUrl = 'https://imgproxy.example.com';
$key = getenv('IMGPROXY_KEY');
$salt = getenv('IMGPROXY_SALT');

$src = 'http://example.com/image.jpg';

$signer = new KeyPair($key, $salt);
$imgProxy = new ImgProxy($imgProxyBaseUrl, $signer);

$builder = $imgProxy->urlBuilder($src);
$builder = $builder->with(
    new Dpr(2),
    new Quality(90),
    new Width(300),
    new Height(400)
);
    
$url = $builder->build()->__toString();  // encoded url
$url = $builder->encoded(false)->build()->__toString(); // plain url

# example: /9SaGqJILqstFsWthdP/dpr:2/q:90/w:300/h:400/aHR0cDovL2V4YW1w/bGUuY29tL2ltYWdl/LmpwZw