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.
I’m dealing with thousands of files, so being able to reduce the size by over 75% (using PixelMator vs ImageMagick) is very important.
Am I missing some obvious ImageMagick settings to achieve better compression? File size is much more important than image quality, and I’m curious as to how PixelMator Pro is getting such better results than ImageMagick (I cannot tell the difference visually between the ImageMagick image and the Pixelmator image).