phpgmagick

gmagick geometry


I was running into the following issue:

// $data contains some image data

$gm = new gmagick;
$gm->readImageBlob($data);
$gm->resizeImage(
    100,
    50,
    gmagick::FILTER_LANCZOS,
    1
);

$gm->readImageBlob($data);
$gm->resizeImage(
    140,
    70,
    gmagick::FILTER_LANCZOS,
    1
);
$output = $gm->getImageBlob();

print_r($gm->getImageGeometry());

will print

Array ( [width] => 100 [height] => 50 )

which is an unexpected result. If I execute exactly the same code with imagick instead of gmagick, I will get different (expected) result

Array ( [width] => 140 [height] => 70 )

Also, interestingly, for the gmagick, if I omit the line

$output = $gm->getImageBlob(); 

then I get the expected image size 140x70..

Am I missing something essential here?

Thanks!


Solution

  • There is one difference between getimageblob method in imagick and gmagick version. The second one resets internal counter, so you will always have dimensions of first added image, not the last.

    gmagick's version of getimageblob

    imagick's version of getimageblob

    Looks like a bug, since there are checks performed on image buffer before reseting counter. Note that this function is not documented anywhere in gmagick section of php net, so it may be unsupported and unmaintained.