PHP code example of hosmelq / imgproxy
1. Go to this page and download the library: Download hosmelq/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/ */
hosmelq / imgproxy example snippets
use HosmelQ\Imgproxy\Imgproxy;
use HosmelQ\Imgproxy\ResizingType;
$url = Imgproxy::create(baseUrl: 'https://imgproxy.example.com')
->format(extension: 'png')
->resize(type: ResizingType::Fit, width: 1200, height: 630)
->build(sourceUrl: 'https://example.com/image.jpg');
use HosmelQ\Imgproxy\Imgproxy;
use HosmelQ\Imgproxy\ResizingType;
use HosmelQ\Imgproxy\Support\Gravity;
$builder = Imgproxy::create(
baseUrl: 'https://imgproxy.example.com',
key: 'b397f17682dea6270ac06941ca1e3f0f',
salt: '68de0f586bdb701cf2458565bf5a6aec'
);
$url = $builder
->format(extension: 'png')
->gravity(gravity: Gravity::smart())
->quality(quality: 80)
->resize(type: ResizingType::Fit, width: 1200, height: 630)
->build(sourceUrl: 'https://example.com/product.jpg');
$shortUrl = $builder
->useShortOptions()
->build(sourceUrl: 'https://example.com/product.jpg');
use HosmelQ\Imgproxy\Imgproxy;
use HosmelQ\Imgproxy\SourceEncoding;
// Plain source (no signature if key/salt are omitted)
$plainUrl = Imgproxy::create(baseUrl: 'https://imgproxy.example.com')
->format(extension: 'png')
->usePlainSource()
->build(sourceUrl: 'https://example.com/product.jpg');
// Encrypted source (pro)
$encryptedUrl = Imgproxy::create(baseUrl: 'https://imgproxy.example.com')
->format(extension: 'png')
->useEncryptedSource()
->withEncryptionKey(key: '1eb5b0e971ad7f45324c1bb15c947cb207c43152fa5c6c7f35c4f36e0c18e0f1')
->build(sourceUrl: 'https://example.com/private.jpg', encoding: SourceEncoding::Encrypted);
use HosmelQ\Imgproxy\Imgproxy;
$signed = Imgproxy::create(
baseUrl: 'https://imgproxy.example.com',
key: 'b397f17682dea6270ac06941ca1e3f0f',
salt: '68de0f586bdb701cf2458565bf5a6aec',
signatureSize: 12,
)
->format(extension: 'png')
->build(sourceUrl: 'https://example.com/product.jpg');
use HosmelQ\Imgproxy\Imgproxy;
$url = Imgproxy::create(baseUrl: 'https://imgproxy.example.com')
->format(extension: 'png')
->useEncryptedSource()
->withEncryptionKey(
key: '1eb5b0e971ad7f45324c1bb15c947cb207c43152fa5c6c7f35c4f36e0f199a',
ivGenerator: fn (): string => random_bytes(16)
)
->build(sourceUrl: 'https://example.com/private.jpg');