very large size
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);
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:

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]);
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.
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
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.
Can you please share a comprehensive example using php-vips library? (to be honest I can't get my head around the Doc)
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]);
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
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.