Skip to content

Latest commit

 

History

History
67 lines (54 loc) · 2.2 KB

README.md

File metadata and controls

67 lines (54 loc) · 2.2 KB

Latest Stable VersionTotal Downloads

img-proxy

Laravel Service Provider for Golang ImgProxy micro-service https://evilmartians.com/chronicles/introducing-imgproxy

Install

Works with Laravel 5.1 - 5.7 / PHP 7.0 - 7.2, probably 7.3 too

  • composer require alexgiuvara/imgproxy
  • copy the ServiceProvider to the providers array in config/app.php. Laravel 5.5 users with auto-discovery may skip this step
AlexGiuvara\ImgProxy\ImgProxyServiceProvider::class,
  • copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="AlexGiuvara\\ImgProxy\\ImgProxyServiceProvider"
  • to generate the secrets, you can use this command: echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')

  • env file:

# img-proxy.base_url
IMGPROXY_URL=https://img-proxy-example.com
# your img-proxy key
IMGPROXY_KEY=943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881
# your img-proxy salt
IMGPROXY_SALT=520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5

This package does not cover the Authorization header.

Usage

helper:

imgProxy('https://www.nasa.gov/sites/default/files/images/528131main_PIA13659_full.jpg', 640, 360)
use AlexGiuvara\ImgProxy\Contracts\ImageSignatureInterface;
use AlexGiuvara\ImgProxy\Image;

Route::get('/img-test', function () {
    $path      = 'https://www.nasa.gov/sites/default/files/images/528131main_PIA13659_full.jpg';
    $width     = 640;
    $height    = 360;
    $pic       = new Image;
    $pic->setOriginalPictureUrl($path)
        ->setWidth($width)
        ->setHeight($height)
        ->setResize('fit')
        ->setGravity('no')
        ->setEnlarge(0)
        ->setExtension('png');
    app()->instance(Image::class, $pic);
    $signature = app(ImageSignatureInterface::class);

    echo '
    Resized: <img src="' . config('img-proxy.base_url') . $signature->take() . '" alt="Resized">
    <br>
    Original: <img src="' . $path . '" alt="Original">
    ';

});