Via Composer
$ composer require hifisaputra/laravel-helpers
// Image helpers
$image = Helpers::image($request->imagefile)
/**
* Change directory path using laravel's helper functions
*
* Parameters:
* (string) - default (public_path())
*
*/
$image->path(storage_path())
/**
* Change the folder path
*
* Parameters:
* (string) - default ('images')
*/
$image->folder('images/profile')
/**
* Add encoding
*
* Parameters:
* (string) Here's a list of encoding format
* supported by [Intervention Image](http://image.intervention.io)
*
* jpg — return JPEG encoded image data
* png — return Portable Network Graphics (PNG) encoded image data
* gif — return Graphics Interchange Format (GIF) encoded image data
* tif — return Tagged Image File Format (TIFF) encoded image data
* bmp — return Bitmap (BMP) encoded image data
* ico — return ICO encoded image data
* psd — return Photoshop Document (PSD) encoded image data
* webp — return WebP encoded image data
* data-url — encode current image data in data URI scheme (RFC 2397)
*
* (integer) Define the quality of the encoded image optionally.
* Data ranging from 0 (poor quality, small file) to 100 (best quality, big file).
*/
$image->encode('jpg', 95)
/**
* Add prefix to filename
*
* Parameters:
* (string)
*/
$image->prefix('user-')
/**
* Save the image
* Return the image's name
*/
$image->save();
dd($image) // '/images/profile/user-5a9d24bb389ae.jpg'
/**
* Save the image with thumbnail
* Return an array of the image's name and the thumbnail's name
*/
$image->saveWithThumbnail();
dd($image)
/**
* [
* 'originalName' : '/images/profile/user-5a9d24bb389ae.jpg',
* 'thumbnailName' : '/images/profile/user-5a9d24bb389ae_tn.jpg'
* ]
*/
// Delete helpers
/**
* Delete file from the given path
* @param $path can be array of strings or just a string.
*/
Helpers::delete($path);
//Config writer
/**
* Write laravel config file
*
* credit: https://github.com/daftspunk/laravel-config-writer
*
* @param array
*/
Helpers::config()->write(['app.locale' => 'en']);
public function store(Request $request)
{
$blog = new Blog();
$blog->user_id = Auth::user()->id;
if ($request->image) {
$image = Helpers::image($request->image)->folder('images/blogs')->encode('jpg', 80)->saveWithThumbnail();
// the image files will be saved inside public/images/blogs
$blog->originalUrl = $image['originalName'];
$blog->previewUrl = $image['thumbnailName'];
}
$blog->fill($request->translations);
$blog->save();
}
The MIT License (MIT). Please see License File for more information.