alcodo / Powerimage by approached

Laravel Package to create a dynamic image handler
18,282
22
2
Package Data
Maintainer Username: approached
Maintainer Contact: alexejkloos@gmail.com (Alexej Kloos)
Package Create Date: 2016-01-11
Package Last Update: 2021-03-29
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-14 15:03:55
Package Statistics
Total Downloads: 18,282
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 22
Total Watchers: 2
Total Forks: 5
Total Open Issues: 0

Powerimage

Powerimage is a dynamic image handler for laravel. It uses the package thephpleague/glide for convert and spatie/image-optimizer for optimize the image.

After the installation you can request any image that you have uploaded in laravel. Example:
example.com/images/cat.jpg (Original)
example.com/images/cat_w=200&h=200.jpg (Convert)

The workflow is very simple. If image isn't found, laravel throw a exception. This package creates only one time this image. And on the next request the image will return form your webserver like nginx (fast response).

Structure:

{domain}/{path}/{fileimage name}_{resize parameter}.{extension}

Delimiter: _

Installation

Add packages:

    composer require alcodo/powerimage:dev-master

Add powerimage handler in app/Exceptions/Handler.php:

    public function render($request, Exception $exception)
    {
        PowerImage::check($request, $exception);

        return parent::render($request, $exception);
    }

And by the way you can inlcude or exclude paths that you want use powerimage example:

    public function render($request, Exception $exception)
    {
        if (PowerImage::include ($request, ['/images/*', '/gallery/*'])) {
            PowerImage::check($request, $exception);
        }

        // or

        if (PowerImage::exclude($request, ['/user/*'])) {
            PowerImage::check($request, $exception);
        }

        return parent::render($request, $exception);
    }

Helper

Create powerimage path helper:

    powerimage('images/video.png', ['w' => 200, 'h' => 350]);
    
    // outut
    'images/video_w=200&h=350.png'
    
    // or direct in blade template
    <img class="img-fluid" src="{{ powerimage(Storage::url($image->filepath), ['w'=> 260, 'h' => 260])  }}" alt=""/>

License

The MIT License (MIT). Please see LICENSE for more information.