**how to create image thumbnails i use different library but thumbnail not create **
public function store(Request $request){
$user_id = \Auth::user()->id;
$image = new Image();
$this->validate($request, [
'title' => 'required',
'description' => 'required',
'image' => 'required'
]);
$image->title = $request->title;
$image->description = $request->description;
$image->user_id = $user_id;
if($request->hasFile('image')) {
$file = Input::file('image');
//getting timestamp
$timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
$name = $timestamp. '-' .$file->getClientOriginalName();
$image->filePath = $name;
$file->move(public_path().'/images/', $name);
}
$image->save();
return $this->upload()->with('success', 'Image Uploaded Successfully');
}
** **how to create image thumbnails i use different library but thumbnail not create ****
I'll suggest you to use the intervention/image
package, it pairs very nicely with Laravel
.
After you install it, here is an example of uploading and saving an image and creating a thumbnail out of it.
$image = Image::make(Input::file('photo')->getRealPath());
$image->save(public_path('photos/'. $id .'.jpg'));
$image->fit(300, 200)->save(public_path('photos/'. $id .'-thumbs.jpg'));
https://github.com/Intervention/image
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With