masteryuri / laravel-pub-preview
Get resized image from public directory
dev-master / 1.0.x-dev
2016-04-10 17:30 UTC
Requires
- php: ~5.5|~7.0
- illuminate/support: ~5.1
Requires (Dev)
- phpunit/phpunit: 4.*
- scrutinizer/ocular: ~1.1
- squizlabs/php_codesniffer: ~2.3
This package is not auto-updated.
Last update: 2024-12-13 20:44:19 UTC
README
Component get resized images from public (storage) directory.
You upload image and use it for preview:
<img src="{{ asset('img/photo1.jpg') }}" alt="Preview"> <img src="{{ asset($article->preview) }}" alt="Preview">
But usually image is too big so you have to generate smaller files:
<img src="{{ asset('img/photo1_100x100.jpg') }}" alt="Preview"> <img src="{{ asset($article->preview_100x100) }}" alt="Preview">
This library lets you to simplify it and make it on fly:
<img src="{{ pub_review('img/photo1.jpg', 100, 100, "scale") }}" alt="Preview"> <img src="{{ pub_review($article->preview, 100, 100, "scale") }}" alt="Preview">
Also you can configure image that must be shown if requested image doesn't exists.
@todo watermark
How it works
Algotitm:
pub_review()
generates url to library controller action.- Controller checks if it has resized image. If no - it generates resized image and saves it to temporaty directory.
- Controller returns resized image from temporary directory.
Parameters of pub_review()
- Relative path to image file.
- Require width in pixels.
- Require height in pixels.
- Required resize mode.
Available modes are 'scale', 'fitin', 'fitout':
Installation
Via Composer
$ composer require masteryuri/laravel-pubpreview
Add service provider into /config/app.php
:
'MasterYuri\PubPreview\ServiceProvider',
Publish config and resources:
php artisan vendor:publish --provider="MasterYuri\PubPreview\ServiceProvider"
Configuration
Configuration file is 'pub-preview.php'. It has comments that describe all parameters.
License
The MIT License (MIT). Please see License File for more information.