Create image thumbnails i laravel 5.0

** How to create thumbnails of images, I use a different library, but I do not create a sketch **

 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 thumbnails of images, I use another library, but I do not create a sketch ****

+4
source share
1 answer

I suggest you use the package intervention/image, it goes well with Laravel.

After installing it, here is an example of loading and saving an image and creating a sketch from 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

+9
source

Source: https://habr.com/ru/post/1626513/


All Articles