1. Go to this page and download the library: Download mperonnet/imgproxy-php 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/ */
mperonnet / imgproxy-php example snippets
use Mperonnet\ImgProxy\UrlBuilder;
use Mperonnet\ImgProxy\Options\Width;
use Mperonnet\ImgProxy\Options\Height;
use Mperonnet\ImgProxy\Options\Quality;
use Mperonnet\ImgProxy\Options\Dpr;
$key = getenv('IMGPROXY_KEY');
$salt = getenv('IMGPROXY_SALT');
$src = 'http://example.com/image.jpg';
$builder = UrlBuilder::signed($key, $salt);
$builder = $builder->with(
new Dpr(2),
new Quality(90),
new Width(300),
new Height(400)
);
$url = $builder->url($src); // Base64-encoded URL
$url = $builder->usePlain()->url($src); // Plain URL
$url = $builder->url($src, 'png'); // Change image format
use Mperonnet\ImgProxy\Options\InfoOptions;
// Basic info
$infoUrl = $builder->info()->with(InfoOptions::basic())->url($src);
// Complete info
$infoUrl = $builder->info()->with(InfoOptions::complete())->url($src);
// Custom info
$infoUrl = $builder->info()->with(
new InfoOptions(
true, // size
true, // format
true, // dimensions
false, // exif
false, // iptc
false, // xmp
true, // video_meta
true // detect_objects
)
)->url($src);
use Mperonnet\ImgProxy\Options\Resize;
use Mperonnet\ImgProxy\Options\Blur;
use Mperonnet\ImgProxy\Options\Watermark;
// First resize, then blur and add watermark
$url = $builder
->with(new Resize('fit', 300, 300))
->pipeline(
new Blur(10),
Watermark::southEast(0.7)
)
->url($src);
use Mperonnet\ImgProxy\Options\Resize;
use Mperonnet\ImgProxy\Options\Size;
use Mperonnet\ImgProxy\Options\Width;
use Mperonnet\ImgProxy\Options\Height;
use Mperonnet\ImgProxy\Options\MinWidth;
use Mperonnet\ImgProxy\Options\MinHeight;
use Mperonnet\ImgProxy\Options\Zoom;
use Mperonnet\ImgProxy\Options\Dpr;
$builder->with(
new Resize('fill', 300, 400, true, false),
new Size(300, 400, true, false),
new Width(300),
new Height(400),
new MinWidth(200),
new MinHeight(200),
new Zoom(1.5),
new Dpr(2)
);
use Mperonnet\ImgProxy\Options\Adjust;
use Mperonnet\ImgProxy\Options\Brightness;
use Mperonnet\ImgProxy\Options\Contrast;
use Mperonnet\ImgProxy\Options\Saturation;
$builder->with(
new Adjust(10, 1.1, 0.9),
new Brightness(10),
new Contrast(1.1),
new Saturation(0.9)
);
use Mperonnet\ImgProxy\Options\Background;
use Mperonnet\ImgProxy\Options\Blur;
use Mperonnet\ImgProxy\Options\Sharpen;
use Mperonnet\ImgProxy\Options\Monochrome;
use Mperonnet\ImgProxy\Options\Duotone;
use Mperonnet\ImgProxy\Options\Colorize;
use Mperonnet\ImgProxy\Options\Gradient;
use Mperonnet\ImgProxy\Support\Color;
$builder->with(
new Background(new Color(255, 255, 255)),
new Blur(5),
new Sharpen(0.7),
new Monochrome(0.8, 'b3b3b3'),
new Duotone(0.8, '000000', 'ffffff'),
new Colorize(0.5, '3498db', true),
new Gradient(0.7, 'ff0000', 45, 0.2, 0.8)
);
use Mperonnet\ImgProxy\Options\Format;
use Mperonnet\ImgProxy\Options\Quality;
use Mperonnet\ImgProxy\Options\FormatQuality;
use Mperonnet\ImgProxy\Options\Autoquality;
use Mperonnet\ImgProxy\Options\MaxBytes;
$builder->with(
new Format('webp'),
new Quality(85),
new FormatQuality([
'jpeg' => 85,
'webp' => 80,
'avif' => 60
]),
Autoquality::dssim(0.02, 70, 85, 0.001),
new MaxBytes(100000)
);
use Mperonnet\ImgProxy\Options\BlurDetections;
use Mperonnet\ImgProxy\Options\DrawDetections;
$builder->with(
new BlurDetections(5, ['face']),
new DrawDetections(true, ['face', 'cat'])
);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.