MagickWand Gravity Crop Bug? MagickTransformImage?

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
maqr

MagickWand Gravity Crop Bug? MagickTransformImage?

Post by maqr »

My goal is to do a gravity-crop, like "convert input.jpg -gravity center -crop 50x50+0+0 output.jpg" using MagickWand.

I believe this code should do it, but it doesn't honor my gravity request, instead I always get the top left corner of the image.

Either this is a bug, or there is some other method I am unaware of to do gravity crops with MagickWand.

Code: Select all

#include <wand/MagickWand.h>

int main()
{
   MagickWand *m_wand = NewMagickWand();
   MagickWand *t_wand = NewMagickWand();

   MagickReadImage( m_wand, "input.jpg" );

   MagickSetGravity( m_wand, CenterGravity );

   t_wand = MagickTransformImage( m_wand, "50x50+0+0", "" );

   MagickWriteImage( t_wand, "output.jpg" );

   m_wand = DestroyMagickWand( m_wand );

   return 0;
}
Tested on 6.4.3-6.

Any thoughts would be appreciated.

--maqr
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Post by magick »

There is a missing method, MagickSetImageGravity(). Until we add this method, move MagickSetGravity() before MagickReadImage().
maqr

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Post by maqr »

Success!

Thanks very much :)
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Post by el_supremo »

FYI: you have a couple of memory leaks in your code.

1. When you declare t_wand don't initialize it to NewMagickWand because MagickTransformImage will return a new wand anyway.
MagickWand *t_wand;

2. At the end of the program you should destroy t_wand as well:
t_wand = DestroyMagickWand( t_wand );

Pete
Post Reply