Kabaneri
Kabaneri

Reputation: 15

Laravel intervention/image doesn't resize image

I am trying to use laravel intervention plugin. I installed it without problem but can't use it. I am trying to make a test function which returns resized image, but without success; I think the problem may be in image path, please help me fix my code.

function test($img)
{
   /* $img = Image::make('public/image1.jpg');
    $img->resize(300, 200);
    return $img; */

   $image = Image::make('http://localhost/cms/digital-cms/public/image1.jpg')->resize(200, 200, function ($c) {
        $c->aspectRatio();
        $c->upsize();
    });
    return $image;

    //$h=200; $w=200;
    //return Image::make(public_path('public/image1.jpg')->resize($h, $w)->response('jpg'));
}

Upvotes: 0

Views: 2573

Answers (3)

Irfandi D. Vendy
Irfandi D. Vendy

Reputation: 1004

In my case, I was resizing, cropping (fit) but the final image is still the same as original. Found out that I had to add function encode, to produce the manipulated image

return $image->encode('jpg', 80);

Upvotes: 0

Ahmed Mahmoud
Ahmed Mahmoud

Reputation: 1832

 //get image
 $image=$request->file('image');
 //rename image
 $input = time().'.'.$image->getClientOriginalExtension();
            //your directory to upload
            $destinationPath = 'main/images/company';
            //save and resize image
            $img = Image::make($image->getRealPath());
            $img->resize(20,20, function ($constraint) {
              $constraint->aspectRatio();
              })->save($destinationPath.'/'.$input);

Upvotes: 1

Kliment
Kliment

Reputation: 2270

You should use response function on Image class to return the image

$image = Image::make('http://localhost/cms/digital-cms/public/image1.jpg')->resize(200, 200, function ($c) {
    $c->aspectRatio();
    $c->upsize();
});
return $image->response();

Upvotes: 0

Related Questions