dev-master
9999999-devEasy image upload and thumbnail management
MIT
The Requires
- php >=5.4.0
- illuminate/support ~5.0
- intervention/image ^2.3
The Development Requires
by Proshore Nepal
Wallogit.com
2017 © Pedro Peláez
Easy image upload and thumbnail management
Basic image upload and thumbnail management package for laravel5., (*1)
First, pull in the package through Composer., (*2)
"require": {
"proshore/laravel-image-upload": "dev-master"
}
And then, if using Laravel 5, include the service provider within config/app.php., (*3)
'providers' => [
LaravelImage\ImageUploadServiceProvider::class,
];
And, for convenience, add a facade alias to this same file at the bottom:, (*4)
'aliases' => [
'ImageHelper' => LaravelImage\Image::class,
];
Finally publish the configuration, (*5)
php artisan vendor:publish --provider="LaravelImage\ImageUploadServiceProvider"
You can add default thumbnail configuration to config/laravelimage.php., (*6)
Within your controllers, get access to image upload service via dependency injection, (*7)
class ContentsController extends Controller
{
...
protected $file;
/**
* @param ImageUploadService $file
*/
public function __construct(ImageUploadService $file)
{
...
//set properties for file upload
$this->file = $file;
$this->file->setUploadField('image'); //default is image
$this->file->setUploadFolder('contents'); //default is public/uploads/contents
}
...
And then, in your store or update method you can perform image upload, (*8)
/**
* Store method
*/
public function store(ContentRequest $request)
{
$input = $request->all();
if (Input::hasFile('image') && $this->file->upload()) {
//file is uploaded, get uploaded file info
$uploadedFileInfo = $this->file->getUploadedFileInfo();
...
//do whatever you like with the information
$input = array_merge($input, $uploadedFileInfo);
}
...
}
/**
* Update method
*/
public function update(Request $request, $id)
{
...
if (Input::hasFile('image') && $this->file->upload()) {
...
//remove old files
if ( ! empty($model->file_path)) {
$this->file->clean(public_path($model->file_path), true);
}
}
...
}
Display from already registered thumbnails. It will try to generate new thumb if registered thumbnail doesn't exist., (*9)
{!!
\LaravelImage\LaravelImage::image($model->file_path, $model->image, [
'alt' => $model->original_file_name,
'size' => 'thumb'
])
!!}
Or, create image of custom size at runtime, (*10)
{!!
\LaravelImage\LaravelImage::image($model->file_path, $model->image, [
'alt' => $model->original_file_name,
'size' => [
'custom' => ['w' => 300, 'h' => 200, 'crop' => true]
]
])
!!}
Easy image upload and thumbnail management
MIT