Image::zoom function in Magick++

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
eldiener

Image::zoom function in Magick++

Post by eldiener »

The documentation in Magick++ for the Image::zoom function is pretty sparse:

"zoom const Geometry &geometry_ Zoom image to specified size."

That's it !

Does anybody know what this is supposed to do, as opposed to, let's say, Image::scale among many others Image resizing functions in Magick++ which also take a Geometry ?

Am I supposed to be using the Geometry which takes the % qualifier ? If so, am I supposed to be use the exact same width and height amounts with the % qualifier ?

I would have thought, being the naive person I am, that an image zoom function would just take a single parameter, which would be the amount to zoom as a percentage of the current size, with amounts greater than 100 making the image proportionally larger and amount less than 100 making the image proportioanlly smaller.

I really appreciate that ImageMagick and Magick++ are free, but the online programming docs make it a real chore to figure out what to do unless one is of the "try it out and you might figure it out" school of programming.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Image::zoom function in Magick++

Post by magick »

Zoom accepts a Geometry or string. The string is typically a percentage, for example
  • image.zoom("50%")
reduces an image to 1/2 its size. The algorithm uses a finite impulse response filter to perform the resize. By default Magick++ uses the Lanczos filter when the image size is reduced otherwise the Mitchell filter.
eldiener

Re: Image::zoom function in Magick++

Post by eldiener »

magick wrote:Zoom accepts a Geometry or string. The string is typically a percentage, for example
  • image.zoom("50%")
reduces an image to 1/2 its size. The algorithm uses a finite impulse response filter to perform the resize. By default Magick++ uses the Lanczos filter when the image size is reduced otherwise the Mitchell filter.
That is wonderful, and how I thought it should work.

The documentation for a Geometry string says that it takes the form of:

"<width>x<height>{+-}<xoffset>{+-}<yoffset>{%}{!}{<}{>}"

This suggests to me that both width and height are mandatory, while everything else is optional. But your example of using "50%" shows a single percentage value. Does this mean that both width and height are not mandatory ? Is this the only case where one can specify a single value ? If there are other cases where one can specify a single value, what does specifying a single value mean ?

I am guessing that the generalized rule for specifying a single value is that it refers to both the width and height, so that "50%" is shorthand for "50%x50%" etc. Is this correct ?

If specifying a single value is allowed as you have implied, it would be nice if the online Magick++ documentation for Geometry were updated to reflect this.

Thanks !
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Image::zoom function in Magick++

Post by anthony »

Generally if only one value in a geometry sting is given then the other value is
set to infinity. For resizes geometry is a 'best fit preserving aspect ratio' unless a '!' is given. With percentages. If any percent symbol is given anywhere both width and height are percentage values of the original image.

Basically 50% will result (due to aspect ratio preservation) in 50%x50%
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply