Change in extentImage behavior for new ImageMagick versions?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
pwnedd
Posts: 35
Joined: 2008-09-03T13:03:57-07:00

Change in extentImage behavior for new ImageMagick versions?

Post by pwnedd »

Hi all,

I have some IMagick code which uses "extentImage" to pad an image and position it at one corning of the new expanded image. When testing on a system with a newer version of ImageMagick, however, the direction the offsets push the image seems to have changed.

In both cases I am using the same version of IMagick (3.0.1). The differening factor is the version of ImageMagick for which they were built against.

For example, to offset the example "rose" image by 100 pixels down and over, the following works for older versions of ImageMagick:

Code: Select all

<?php
    header("Content-type: image/png");
    $im = new Imagick();
    $im->newPseudoImage(70, 46, "magick:rose");
    $im->setImageFormat("png");
    $im->extentImage(256, 256, -100, -100);
    echo $im;
?>
With newer versions you would need to use "100" instead of "-100" for the x & y offsets to achieve the same effect.

Verion Info:

Old:
Version: ImageMagick 6.6.2-6 2010-12-02 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP

New:
Version: ImageMagick 6.6.9-8 2011-05-05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

Any ideas why the behavior has changed? I would like to write code that is not dependent on the verison of IM installed. I could probably detect the version installed and use that to decide whether to use positive or negative offsets, but does anyone know of a better way? I know there is a similar method (setImageExtent) but that does not provide support for specifying which direction the padding should occur in.

Thanks,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Change in extentImage behavior for new ImageMagick versi

Post by fmw42 »

Older version probably ignored the minus sign. Shifting down and to the right has always been Plus as far as I know. See http://www.imagemagick.org/Usage/crop/#extent
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Change in extentImage behavior for new ImageMagick versi

Post by anthony »

Extent can also be simulated simply by creating the appropriate background image and then composing the source image onto that in the appropriate way. This is also how border, crop, flatten, mosaic, merge, and even trim, operators work too, just with different ways of calculating the background image size and offset.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply