alcodo / powerimage
Laravel Package to create a dynamic image handler
Installs: 18 286
Dependents: 1
Suggesters: 0
Security: 0
Stars: 22
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- php: >=7.0
- illuminate/support: ^5.5|^5.8|^6.0|^7.0|^8.0
- league/glide: ^1.3
- spatie/image-optimizer: ^1.0
Requires (Dev)
- orchestra/testbench: ^3.5|^4.0|^5.0|^6.0
- phpunit/phpunit: ^5.7|^8.0|^9.0
This package is auto-updated.
Last update: 2024-11-29 04:57:40 UTC
README
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.