php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67258 scaleImage does not work with quantizeImage Imagick::COLORSPACE_GRAY
Submitted: 2014-05-12 13:07 UTC Modified: 2015-02-13 20:55 UTC
From: richard_s_yeo at hotmail dot com Assigned: danack (profile)
Status: Closed Package: imagick (PECL)
PHP Version: Irrelevant OS: Amazon 3.4.73-64.112.amzn1.i686
Private report: No CVE-ID: None
 [2014-05-12 13:07 UTC] richard_s_yeo at hotmail dot com
Description:
------------
Amazon recently upgraded the Amazon Linux AMI 32 bit to include
ImageMagick.i686 0:6.7.8.9-6.14.amzn1
ImageMagick-devel.i686 0:6.7.8.9-6.14.amzn1
This forced us to reinstall imagick so we upgraded to v3.1.2

Just noticed that when shrinking image with scaleImage the attached code does not set to grayscale as it did prior to upgrades.

However if you set $t['width'] = 2010 it does convert to grayscale.

NexTUmvuchVSXe7Y3ThHidh9lGcj.jpg in our example is 2000x2000 pixel image.

We are using PHP 5.3.28

Test script:
---------------
$image = new Imagick();
$image->readImage("NexTUmvuchVSXe7Y3ThHidh9lGcj.jpg");
$t['width'] = 200;
$oldw = $image->getImageWidth(); $oldh = $image->getImageHeight();
$ratiow = $t['width']/$oldw;
$height = round($oldh*$t['width']/$oldw);
if ($height<1) $height=1;
if ($ratiow>1) {
        if (!$image->thumbnailImage($t['width'], $height))
                throw new Exception("image scaling failed");
} else {
        if (!$image->scaleImage($t['width'], $height))
                throw new Exception("image scaling failed");
}
if(!$image->quantizeImage(65536, Imagick::COLORSPACE_GRAY, 0, false, false))
    throw new Exception("conversion to grayscale failed");
file_put_contents("NexTUmvuchVSXe7Y3ThHidh9lGcj-w200g1.jpg", $image);
$image = new Imagick();
$image->readImage("NexTUmvuchVSXe7Y3ThHidh9lGcj.jpg");


Expected result:
----------------
We expect the image to be converted to grayscale.

Actual result:
--------------
Image is not converted to grayscale

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-05 03:10 UTC] danack@php.net
-Status: Open +Status: Verified
 [2015-01-05 03:10 UTC] danack@php.net
This is a bug in the underlying ImageMagick library:

http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=26828&sid=3e1c0f541805a2c6cab425c105825f1c

Basically, when you quantize an image to N colors, where N is greater than the number of pixels in the image, then the image would not be altered, even if you requested the colorspace to be modified as well.

It should be fixed in the next version of ImageMagick.
 [2015-02-13 20:55 UTC] danack@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: danack
 [2015-02-13 20:55 UTC] danack@php.net
I have confirmed that this is fixed in ImageMagick 6.9.0-4.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 10:01:31 2024 UTC