Proportional height resize not working in Magick++
Swiss army knife of image processing
Brought to you by:
bfriesen
I'm not sure if this is really a bug; I'm just getting started with GraphicsMagick.
Here's the problem I'm having: I want to resize an image, keeping aspect ratio, to have a specified width.
The imagemagick command I would use is convert in.jpg -resize 2000x out.jpg
which works as expected.
Using graphicsmagick, with the command gm convert in.jpg -resize 2000x out.jpg
does not work, and simply renders the original image.
This also happens using the STL api.
I'm using an older version of graphicsmagick from ubuntu trusty:
GraphicsMagick 1.3.18 2013-03-10 Q8
What are the dimensions of in.jpg ?
In some versions, the omitted y-dimension isn't handled correctly and the documentation is (or was) ambiguous about that. For any version you can get what you want by using an arbitrarily large y-dimension:
convert in.jpg -resize 2000x32000 out.jpg
This works for ImageMagick also.
Last edit: Glenn Randers-Pehrson 2015-07-27
This problem was fixed on 2014-04-23 and so it was already included in release 1.3.20 as of August 16, 2014. The current release is 1.3.22. Please lobby your OS distribution to update.
Great, thanks for the information.
I built the latest version from SF (1.3.21) and I'm still having the same problem. The command line tool works, but I can't figure out how to make it work using the API.
I've attached a minimal example that shows the problem I'm having.
I build it using:
To be clear, this implemented feature is for the command-line which has no/little efficient access to the current image dimensions. In a C++ program you have complete access to the current image dimensions and can do any necessary math yourself.
This is the C code (from GetMagickGeometry()) which is used to support the feature:
I see that you are using STL function objects, which is way cool. In the mean time, I think that you could create your own function object similar to the existing resizeImage() but which computes the desired size using math similar to GetMagickGeometry(). However, please note that the Magick++ Geometry class is exact (width, height, x, y, are always specified) and it does not internally support a way to know if the width or height dimension is missing. I see that the C library TransformImage() does use GetMagickGeometry() so it seems that all that is needed is an upgrade to the Geometry class to remember/reproduce that width or height is missing.
I did try doing the math myself, but I couldn't seem to get at the image's geometry. I kept getting:
When I called
Image::geometry()
.On the other hand, setting a very large dimension instead of zero does do what I want.
Last edit: tecywiz121 2015-07-29
The image current dimensions are available via the Image rows() and columns() methods. It seems that Image geometry() is used for obscure purposes related to composition (e.g. for DisplaceCompositeOp) and cropping. I need to improve its documentation.
Image placement offset can be obtained via the Image page() method.