Page 1 of 1

efficient canvas resize?

Posted: 2008-07-02T17:04:55-07:00
by koopa
ImageMagick 6.4.2
Magick++

I have a Magick::Image object in memory. I would like to increase the image size (not resampling) by a few rows on top and bottom using the background color. I can't find an efficient way to do this. extent(...) will only add to the bottom and right. border(...) will only add to both sides equally. crop(...) will only decrease the size. I know I must be missing something. Do I really have to create a new image and copy over the old?

-Chris

Re: efficient canvas resize?

Posted: 2008-07-02T17:12:05-07:00
by anthony
extent also allows gravity, and slive lets you add rows and columns to one edge or corner.

See IM Examples, Cutting and Bordering.

For better control, assign the image a 'virtual canvas' with the size and the image position on the canvas wanted, then -flatten to full out that canvas with with background (or 'none' for transparency') of your choice.

See IM examples, Layering Images, Flatten.

All these are in the API's too but that is not where my expertise is.

Re: efficient canvas resize?

Posted: 2008-07-02T17:27:16-07:00
by koopa
Thank you, those examples were my starting point. Gravity and splice (slive?) are not available in the Magick++ API (and have their own problems here). Layers and flattening must be, but it is outside the Magick::Image class. I'll keep struggling in that direction, but advice from someone more familiar would be appreciated.

-Chris

Re: efficient canvas resize?

Posted: 2008-07-02T20:42:56-07:00
by koopa
Digging through the Magick++ code, Magick::Image::extent(...) tosses the Geometry offsets instead of potentially passing them through SetImageExtent(...) to SetImagePixels(...). There may or may not be a reason for this. MagickWand's MagickExtentImage(...) and the command-line tools look like they do handle offsets correctly for extent (not actually tested). Curious.

-Chris