Image controller for laravel application
Controller your images for client request with size, quality, and extenstion with easy way. You no longer need to create an image with multiple sizes, this package is already handling request images with size needed,
Require this package with composer:
composer require flipbox/image-controller
Add the ServiceProvider to the providers array in config/app.php
Flipbox\ImageController\ImageControllerServiceProvider::class,
Add the facade of this package to the $aliases array config/app.php
'ImageController' => Flipbox\ImageController\Facade::class
Copy the package resource to your application with the publish command:
php artisan vendor:publish
your image ready to control :-)
To avoid clashed request, we suggest you to add a little code to the end of your .htaccess
file in public laravel folder
RewriteRule .*\.(jpg|png|gif|tif|bmp)$ index.php [NC,L]
create folder images
to your public folder (however you can change name of folder in config file), and put image to that folder, for example you put image with file name a photo.jpg
, and you can access your photo as usual http://localhost/images/photo.jpg
.
Now you can request image with specify size (thumbnail
,small
,medium
,large
)
http://localhost/images/photo.jpg?size=thumbnail
default width 100pxhttp://localhost/images/photo.jpg?size=small
default width 240pxhttp://localhost/images/photo.jpg?size=medium
default width 500pxhttp://localhost/images/photo.jpg?size=large
default width 1024px
Also you can request image with specify width or height or event bothhttp://localhost/images/photo.jpg?width=320
auto heighthttp://localhost/images/photo.jpg?height=320
auto widthhttp://localhost/images/photo.jpg?width=100&height=320
fixed width and height
Real file extension will be ignored, now you can access your images file with extensions that defined in config or even with no extensionhttp://localhost/images/photo
valid by defaulthttp://localhost/images/photo.jpg
valid by defaulthttp://localhost/images/photo.png
valid by defaulthttp://localhost/images/photo.gif
valid by default
We provide uploader file that make upload file very easy. First parameter is UploadedFile or Base64 Encoding, and second parameter is directory/prefix.
ImageController::upload($request->file, 'profile');
this method will be return string of generated filename str_random(34)
Add model accesor to generate image link.
/**
* Get ProfilePicture.
*
* @param string $value
* @return string
*/
public function getProfilePictureAttribute($value)
{
return ImageController::generateImageUrl($value, 'small');
}