Image filesize after resizing with Imagick and Gmagick

864 views Asked by At

While resizing an image, I have noticed that Imagick and Gmagick produce images with different filesize on HDD with the same options:

$image = new Imagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_imagick.jpg");

outputs an Image with 88kb

$image = new Gmagick("c.jpg");
$image->thumbnailImage(260,195); 
$image->writeImage("c_gmagick.jpg");

outputs an Image with 15kb

Does someone have any idea, why the difference is so huge?

1

There are 1 answers

0
HawkHogan On BEST ANSWER

Try setting the image compression settings prior to resizing.

     $image->setImageCompression(Imagick::COMPRESSION_JPEG);
     $image->setImageCompressionQuality(80);

Additionally, check the size of the resulting image. Comments in the PHP documentation lead me to believe that the automatic fit portion of thumbnailImage does not work as you would expect in IMagick.

From PHP Docs:

The fit functionality of thumbnailImage doesn't work as one would anticipate. Instead, use >this to make a thumbnail that has max of 200x82:

    // Create thumbnail max of 200x82
    $width=$im->getImageWidth();
    if ($width > 200) { $im->thumbnailImage(200,null,0); }

    $height=$im->getImageHeight();
    if ($height > 82) { $im->thumbnailImage(null,82,0); }