efficient canvas resize?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
koopa

efficient canvas resize?

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: efficient canvas resize?

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
koopa

Re: efficient canvas resize?

Post 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
koopa

Re: efficient canvas resize?

Post 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
Post Reply