mardi 3 octobre 2017

Unable to create thumbnail while image is uploading in Laravel

I'm trying to create thumbnail of image while it is uploading. The problem is that the thumbnail isn't created at all. Also is not saved in database.

This is what I have added in my function

    $image = $request->file('image');

    if( $image && $image->isValid()){

        $imagename = str_random(20).'.'.$image->getClientOriginalExtension(); 

        $destinationPath = public_path('/uploads');
        $thumb_img = Image::make($image->getRealPath())->resize(100, 100);
        $thumb_img->save($destinationPath.'/'.$imagename,80);

        $image->move($destinationPath, $imagename);                    
    }

    $item->image = $filename;
    $item->image_thumb = $thumb_img;

It's saves only the original image both places - uploads dir and in database but nothing regarding the thumbnail.

I'm using Intervention package.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire