Resizing rounds down
-
The resizing makes the mistake of rounding down the image dimensions when calculating the size!
For example, a 3000 x 2000 pixel image (3:2 format) should reduce to a 1024 x 683 pixel image, but WordPress reduces it to a 1024 x 682 pixel image. Note that ImageMagick itself does, too.
Why does this matter? Because PhotoShop doesn’t make this mistake, and if you have a design that requires a good quality image, you probably have a lot of 1024×683 images!
Please, it would be great to have the option use ‘properly’ sized images. Here’s a piece of PHP code that does it right :
// Resizes to whichever is larger, width or height if ($w>$h) { $mw = $maxWidth; $mh = round( ($maxWidth/$w)*$h ); } else { $mh = $maxHeight; $mw = round( ($maxHeight/$h)*$w ); } // Resize image using the lanczos resampling algorithm based on width $image->resizeImage($mw,$mh,Imagick::FILTER_LANCZOS,0.9); // Set to use jpeg compression $image->setImageCompression(Imagick::COMPRESSION_JPEG); // Set compression level (1 lowest quality, 100 highest quality) $image->setImageCompressionQuality($jpegquality); // Strip out unneeded meta data //$image->stripImage(); // Writes resultant image to output directory $image->writeImage($f); // Destroys Imagick object, freeing allocated resources in the process
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Resizing rounds down’ is closed to new replies.