nicklog/imgproxy

This library provides a simple way to generate URLs for imgproxy.

1.0.0 2024-12-29 15:21 UTC

This package is auto-updated.

Last update: 2025-05-29 01:49:24 UTC


README

ImgProxy

This is a PHP library that makes it easy to build URL for ImgProxy.

Version Php License Build Status Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads Daily Downloads

Installation

The preferred way to install this extension is through composer.

Either run

composer require nicklog/imgproxy:^1.0

or add this code line to the require section of your composer.json file:

"nicklog/imgproxy": "^1.0"

Usage

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

License

Released under the MIT license.