Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create image thumbnails i laravel 5.0

Tags:

php

laravel-5

**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 ****

like image 727
Amjad Sarwar Avatar asked Jan 29 '16 11:01

Amjad Sarwar


Video Answer


1 Answers

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

like image 50
user2094178 Avatar answered Oct 02 '22 03:10

user2094178