php-vips icon indicating copy to clipboard operation
php-vips copied to clipboard

very large size

Open sadektouati opened this issue 4 years ago • 9 comments

It's my first time using VIPS.

I'm trying to convert images from jpg to avif.

My issue is that the size of the generated image is around FOUR times the original image size (same width, same height)

What I'm doing wrong?

$filename = '1638389769417678.jpg'; $image = Vips\Image::newFromFile($filename); $image->writeToFile('jpegto.avif', .8);

sadektouati avatar Dec 07 '21 13:12 sadektouati

Hi @sadektouati,

It depends a bit on the image, but they should be very roughly equivalent in size. I see:

$ vips copy astronauts.png x.avif
$ vips copy astronauts.png x.jpg
$ ls -l x.avif x.jpg 
-rw-r--r-- 1 john john 170878 Dec  7 13:56 x.avif
-rw-r--r-- 1 john john 138095 Dec  7 13:57 x.jpg

Using this standard test image:

astronauts

If you want to make the images smaller, turn the Q factor down. For example:

$ vips copy astronauts.png  x.avif[Q=40]
$ ls -l x.avif
-rw-r--r-- 1 john john 127693 Dec  7 13:55 x.avif

In PHP, it's:

$image->writeToFile(filename, ['Q' => 40]);

jcupitt avatar Dec 07 '21 14:12 jcupitt

In my case,

The original jpg file is 12k where the output file is 70k , it's avif and it's supposed to be smaller than jpg.

I have no clue as to the solution of this.

sadektouati avatar Dec 08 '21 12:12 sadektouati

If you can somehow share this file, I could have a look.

AVIF will only be smaller then JPG if you set the compression options. They are documented here:

https://www.libvips.org/API/current/VipsForeignSave.html#vips-heifsave

jcupitt avatar Dec 08 '21 13:12 jcupitt

Can please share a link to a tutorial (using php-vips)

And here are the images: Original Output

sadektouati avatar Dec 08 '21 22:12 sadektouati

Hi, are those the right images? Your original is 21kb. I tried converting to avif:

$ ls -l car.jpg 
-rw-rw-r-- 1 john john 21834 Dec  9 13:03 car.jpg
$ vips copy car.jpg x.avif
$ ls -l x.avif
-rw-r--r-- 1 john john 25898 Dec  9 13:03 x.avif

So the avif is only very slightly larger.

jcupitt avatar Dec 09 '21 13:12 jcupitt

Can you please share a comprehensive example using php-vips library? (to be honest I can't get my head around the Doc)

sadektouati avatar Dec 09 '21 18:12 sadektouati

Yes, the php docs aren't great, unfortunately. It's a limitation of phpdoc.

You need eg.:

$filename = '1638389769417678.jpg'; 
$image = Vips\Image::newFromFile($filename);
$image->writeToFile('jpegto.avif', ['Q' => 40]);

jcupitt avatar Dec 09 '21 18:12 jcupitt

Thank you very much.

I tried different 'Q' values: 5, 10, 15 .... Still it doesn't work. It's always avif is way bigger than the original image

sadektouati avatar Dec 10 '21 00:12 sadektouati

Are you using libheif v1.7.0 from RPM Fusion? If so, you might have encountered this bug: https://github.com/strukturag/libheif/issues/274.

kleisauke avatar Dec 10 '21 09:12 kleisauke