Image: encode() is not working

Created on 2 Mar 2018  路  6Comments  路  Source: Intervention/image

Hi

Am on Laravel 5.5 with image type Imagick, even I have installed libwebp, WebP in my Ubuntu 16.04.

I would like to resize and change the extension of the file, so I made a even and listener to achieve it.
So created a listener HasUploadedImageListener and in handle()

EventServiceProvider
ImageWasUploaded::class => [ HasUploadedImageListener::class ]

inside the handle()
$img = Image::make( $event->path() ); $img->encode( 'jpg' ); $img->resize( 720, null, function ( $constraint ) { $constraint->aspectRatio(); } ); $img->save();

But its not saving to jpg but its resizing it to 720px. Even I tried to apply the encode into the vendor file ResizeController.php but nothing is working on encode().

Kindly suggestion me how to fix this.

Most helpful comment

Same for me. Using imagick Laravel 5.8.
encode() does not seem to work.

$manager = new ImageManager(['driver' => 'imagick']);
$uploadImage = $manager->make($file);
$uploadImage = $uploadImage->encode('jpg', 100);

Mime still original such as tiff.

All 6 comments

Same problem. Version 2.5.0. Simple:
Image::make('mypngfile_wo_ext')->encode('jpg', 85)->save(); # Mime still image/png.

Same for me. Using imagick Laravel 5.8.
encode() does not seem to work.

$manager = new ImageManager(['driver' => 'imagick']);
$uploadImage = $manager->make($file);
$uploadImage = $uploadImage->encode('jpg', 100);

Mime still original such as tiff.

No progress on this huh?
Laravel 6.0

$img = Image::make($upload); 
if($img->filesize() > 100000){
  $img->encode('jpg', 5);
}
$img->save($path);

Should result in a pretty low quality jpg but saves the same as without encode.

Same issue here with Laravel 6 and 2.5.1.

Hi

Am on Laravel 5.5 with image type Imagick, even I have installed libwebp, WebP in my Ubuntu 16.04.

I would like to resize and change the extension of the file, so I made a even and listener to achieve it.
So created a listener HasUploadedImageListener and in handle()

EventServiceProvider
ImageWasUploaded::class => [ HasUploadedImageListener::class ]

inside the handle()
$img = Image::make( $event->path() ); $img->encode( 'jpg' ); $img->resize( 720, null, function ( $constraint ) { $constraint->aspectRatio(); } ); $img->save();

But its not saving to jpg but its resizing it to 720px. Even I tried to apply the encode into the vendor file ResizeController.php but nothing is working on encode().

Kindly suggestion me how to fix this.

I think the issue is that you actually do not save the encoded but the original image.

This should work:

$img = Image::make( $event->path() ); 
$encodedImage = $img->encode( 'jpg' ); 
$encodedImage->resize( 720, null, function ( $constraint ) { $constraint->aspectRatio(); } ); 
$encodedImage->save();

Same issue. Version 2.5.1 with Laravel 7.24.0.

I tried bellow code and this worked.

$img = Image::make(storage_path("app/xxxxx.jpg"));
$img->save(storage_path("app/xxxxx.jpg"), 20);

The quality option of encode() is not working...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anil-kumar-pal picture anil-kumar-pal  路  6Comments

p4bloch picture p4bloch  路  6Comments

samwalshnz picture samwalshnz  路  8Comments

johnvoncolln picture johnvoncolln  路  7Comments

cherrycoding picture cherrycoding  路  3Comments