librelist archives

« back to archive

Crash when using MagickTransformImage

Crash when using MagickTransformImage

From:
Mitch Lindgren
Date:
2012-09-04 @ 02:54
Hi,
I'm trying to use Wand to apply MagickTransformImage to an image.  I'm not
very experienced with MagickWand, nor with using C APIs via Python
wrappers, so I might be doing something wrong, but Python keeps crashing
with a segmentation fault when I try to do the transformation.  Here is my
code:

      img = Image(filename=photo_local_path(photo, 'original'))



      for size_name, geometry in PHOTO_SIZES.items():



          # Ignore the original size, as it has necessarily already been
saved
          if geometry is None: continue



          with img.clone() as cloned_img:

              print geometry # Debug

              wand.api.library.MagickTransformImage(cloned_img.wand,
'100%', geometry) # Crash here
              cloned_img.save(filename=photo_local_path(photo, size_name))


I'm running Python 2.7.2 on Mac OS X Mountain Lion.  I have debugging
information, including a stack trace, that I can send privately; I can't
include it in this message because the list rejects it for being too big.

Am I doing something wrong here, or is this a bug?

Thanks,
Mitch Lindgren

Re: Crash when using MagickTransformImage

From:
Mitch Lindgren
Date:
2012-09-04 @ 04:30
Okay, so I took a look at the Wand source and figured this out.  Currently,
no argtypes or restype are defined for MagickTransformImage, which is why
the segfault occurs.  I forked the repository and changed this, and created
a pull request: https://github.com/dahlia/wand/pull/50.  I'm not sure how
to run the tests, but the change is pretty isolated, and I did a brief test
of my own to check that MagickTransformImage works with my changes:

>>> import wand.api
>>> wand.api.library.MagickTransformImage.argtypes
[<class 'ctypes.c_void_p'>, <class 'ctypes.c_char_p'>, <class
'ctypes.c_char_p'>]
>>> wand.api.library.MagickTransformImage.restype
<class 'ctypes.c_void_p'>
>>> import wand.image
>>> im = wand.image.Image(filename='/Users/mitch/Pictures/mitch_kh.jpg')
>>> x = wand.api.library.MagickTransformImage(im.wand, '100%', 'x256')
>>> wand.api.library.MagickWriteImage(x, '/Users/mitch/Desktop/test.jpg')
1

On Mon, Sep 3, 2012 at 7:54 PM, Mitch Lindgren <lindgren.mitch@gmail.com>wrote:

> Hi,
> I'm trying to use Wand to apply MagickTransformImage to an image.  I'm not
> very experienced with MagickWand, nor with using C APIs via Python
> wrappers, so I might be doing something wrong, but Python keeps crashing
> with a segmentation fault when I try to do the transformation.  Here is my
> code:
>
>       img = Image(filename=photo_local_path(photo, 'original'))
>
>
>
>       for size_name, geometry in PHOTO_SIZES.items():
>
>
>
>           # Ignore the original size, as it has necessarily already been
> saved
>           if geometry is None: continue
>
>
>
>           with img.clone() as cloned_img:
>
>               print geometry # Debug
>
>               wand.api.library.MagickTransformImage(cloned_img.wand,
> '100%', geometry) # Crash here
>               cloned_img.save(filename=photo_local_path(photo, size_name))
>
>
> I'm running Python 2.7.2 on Mac OS X Mountain Lion.  I have debugging
> information, including a stack trace, that I can send privately; I can't
> include it in this message because the list rejects it for being too big.
>
> Am I doing something wrong here, or is this a bug?
>
> Thanks,
> Mitch Lindgren
>

Re: [wand] Crash when using MagickTransformImage

From:
Hong Minhee
Date:
2012-09-04 @ 10:46
Hi,

Thanks for your contribution.  As I replied in the pull request, it should
provide a higher-level API with unit tests for it as well.  If you 
couldn’t do that for any reasons, we can’t merge your patch until one of 
other contributors (including me) continues your contribution.

If you commit and push continuous works for it I will review the patch.

Regards,
Hong Minhee

On Sep 4, 2012, at 1:30 PM, Mitch Lindgren <lindgren.mitch@gmail.com> wrote:

> Okay, so I took a look at the Wand source and figured this out.  
Currently, no argtypes or restype are defined for MagickTransformImage, 
which is why the segfault occurs.  I forked the repository and changed 
this, and created a pull request: https://github.com/dahlia/wand/pull/50.
I'm not sure how to run the tests, but the change is pretty isolated, and 
I did a brief test of my own to check that MagickTransformImage works with
my changes:
> 
> >>> import wand.api
> >>> wand.api.library.MagickTransformImage.argtypes
> [<class 'ctypes.c_void_p'>, <class 'ctypes.c_char_p'>, <class 
'ctypes.c_char_p'>]
> >>> wand.api.library.MagickTransformImage.restype
> <class 'ctypes.c_void_p'>
> >>> import wand.image
> >>> im = wand.image.Image(filename='/Users/mitch/Pictures/mitch_kh.jpg')
> >>> x = wand.api.library.MagickTransformImage(im.wand, '100%', 'x256')
> >>> wand.api.library.MagickWriteImage(x, '/Users/mitch/Desktop/test.jpg')
> 1
> 
> On Mon, Sep 3, 2012 at 7:54 PM, Mitch Lindgren <lindgren.mitch@gmail.com> wrote:
> Hi,
> I'm trying to use Wand to apply MagickTransformImage to an image.  I'm 
not very experienced with MagickWand, nor with using C APIs via Python 
wrappers, so I might be doing something wrong, but Python keeps crashing 
with a segmentation fault when I try to do the transformation.  Here is my
code:
> 
>       img = Image(filename=photo_local_path(photo, 'original'))

>

>       for size_name, geometry in PHOTO_SIZES.items():

>

>           # Ignore the original size, as it has necessarily already been
saved        
>           if geometry is None: continue

>

>           with img.clone() as cloned_img:

>               print geometry # Debug

>               wand.api.library.MagickTransformImage(cloned_img.wand, 
'100%', geometry) # Crash here
>               cloned_img.save(filename=photo_local_path(photo, size_name))     
> 
> I'm running Python 2.7.2 on Mac OS X Mountain Lion.  I have debugging 
information, including a stack trace, that I can send privately; I can't 
include it in this message because the list rejects it for being too big.
> 
> Am I doing something wrong here, or is this a bug?
> 
> Thanks,
> Mitch Lindgren
>