I'm converting PNG images to WebP and trying to do maximum compression with ImageMagick.
My PHP code to run ImageMagick looks like this:
$imagick = new Imagick($filePath);
// Set WebP format and quality
$imagick->setImageFormat('webp');
$imagick->setImageCompressionQuality(0);
// Set WebP-specific compression parameters
$imagick->setOption('webp:method', '6'); // Maximum compression speed (0-6)
// Remove unnecessary metadata to reduce size further
$imagick->stripImage();
$outputFile = $outputDir . '/' . $fileName . '.webp';
$imagick->writeImage($outputFile);
From a 600 KB PNG source file, this produces a 217 KB WebP file.
However, when I do this conversion manually in PixelMator Pro on macOS, I get a file size of just 45 KB ("Export for Web" as WebP with quality of 0, no other settings). When I open the 217 KB WebP file generated by ImageMagick in PixelMator Pro and use "Export for Web" with quality of 0, I get a file of 56 KB. So I wondered why PixelMator is so much more efficient than ImageMagick.
So I tried setImageCompressionQuality(1), and then ImageMagick produced a file of 58 KB, effectively the same as PixelMator.
Why does ImageMagick produce larger file sizes for 0 quality? I confirmed this behavior on ImageMagick 7.1.1-41 on macOS and 6.9.11-60 on debian.
setImageCompressionQuality(0)producing large files-- setting the quality to1or2or5produces much smaller files.