Page 1 of 1

MagickWand Gravity Crop Bug? MagickTransformImage?

Posted: 2008-09-03T19:53:34-07:00
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

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Posted: 2008-09-04T08:47:53-07:00
by magick
There is a missing method, MagickSetImageGravity(). Until we add this method, move MagickSetGravity() before MagickReadImage().

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Posted: 2008-09-04T09:26:35-07:00
by maqr
Success!

Thanks very much :)

Re: MagickWand Gravity Crop Bug? MagickTransformImage?

Posted: 2008-09-07T14:15:54-07:00
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