PHP code example of hosmelq / laravel-imgproxy

1. Go to this page and download the library: Download hosmelq/laravel-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 / laravel-imgproxy example snippets


use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy;
use HosmelQ\Imgproxy\ResizingType;

$url = Imgproxy::builder()
    ->resize(ResizingType::Fill, 300, 300)
    ->quality(80)
    ->build('https://example.com/avatar.jpg');

use HosmelQ\Imgproxy\ResizingType;

use function HosmelQ\Imgproxy\Laravel\imgproxy;

$url = imgproxy()
    ->resize(ResizingType::Fit, 1200)
    ->build('https://example.com/header.jpg');

$url = Imgproxy::builder()
    ->format('webp')
    ->build('https://example.com/photo.jpg', 'webp');

use HosmelQ\Imgproxy\ResizingType;
use Illuminate\Support\Facades\Storage;

$url = Storage::disk('public')
    ->imgproxy('images/header.jpg')
    ->resize(ResizingType::Fit, 1200)
    ->build('webp');

$url = Storage::disk('s3')
    ->imgproxy('private/report.png')
    ->temporary(now()->addMinutes(10))
    ->build();

use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy;
use Illuminate\Support\Facades\Storage;

$url = Imgproxy::infoBuilder()
    ->dimensions()
    ->size()
    ->build('https://example.com/photo.jpg');

$url = Storage::disk('public')
    ->imgproxyInfo('photo.jpg')
    ->dimensions()
    ->build();

use HosmelQ\Imgproxy\Laravel\Facades\Imgproxy;

Imgproxy::buildIvUsing(function (string $sourceUrl): string {
    $hash = hash_hmac('sha256', $sourceUrl, config()->string('app.key'), true);

    return substr($hash, 0, 16);
});

use HosmelQ\Imgproxy\Laravel\ImgproxyManager;
use HosmelQ\Imgproxy\ResizingType;

final class AvatarUrl
{
    public function __construct(private ImgproxyManager $imgproxy) {}

    public function handle(string $source): string
    {
        return $this->imgproxy->builder()
            ->resize(ResizingType::Fill, 300, 300)
            ->build($source);
    }
}
bash
php artisan vendor:publish --tag=imgproxy-config