image icon indicating copy to clipboard operation
image copied to clipboard

encode() is not working

Open mavinothkumar opened this issue 7 years ago • 9 comments

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.

mavinothkumar avatar Mar 02 '18 10:03 mavinothkumar

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

EligiusSantori avatar Jun 28 '19 20:06 EligiusSantori

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.

livingos avatar Jul 17 '19 14:07 livingos

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.

andrewwindfall avatar Oct 08 '19 21:10 andrewwindfall

Same issue here with Laravel 6 and 2.5.1.

davidparedes avatar Apr 19 '20 23:04 davidparedes

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();

cplewnia avatar May 24 '20 12:05 cplewnia

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

MizukiMatsutani avatar Sep 15 '20 10:09 MizukiMatsutani

Same issue.

PHP code use this package "name": "intervention/image", "version": "2.5.1",

kythuatwebso avatar Jun 28 '21 01:06 kythuatwebso

still, issue? damn anyone, any luck?

salmanrajz avatar Jul 11 '21 16:07 salmanrajz

works without saving: $img = Image::make('some image'); $jpgImg = Image::make((string)$img->encode('jpg', 75));

rlucan avatar Apr 25 '22 12:04 rlucan

This issue should be resolved as of version 3.

olivervogel avatar Dec 27 '23 14:12 olivervogel