Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image.transform does not preserve animations #251

Closed
pthimon opened this issue Jul 14, 2015 · 2 comments
Closed

Image.transform does not preserve animations #251

pthimon opened this issue Jul 14, 2015 · 2 comments
Labels
Milestone

Comments

@pthimon
Copy link

pthimon commented Jul 14, 2015

It's expected that the transform does the same as the resize, however the animation is lost when using transform.

with Image(filename='original.gif') as img:
    #img.resize(50,50)
    img.transform(resize='50x50')
    img.save(filename='converted.gif')

I had a look at Image.transform, and it looks like new_wand is being used as the source and the destination. In the code below, I've placed the result of the transformed image into a new resized_wand image and it appears to work, although I am unsure whether new_wand gets destroyed correctly.

# wand/image.py L:1405
if self.animation:
        resized_wand = None
        new_wand = library.MagickCoalesceImages(self.wand)
        length = len(self.sequence)
        for i in xrange(length):
            library.MagickSetIteratorIndex(new_wand, i)
            if i:
                library.MagickAddImage(resized_wand, library.MagickTransformImage(new_wand, crop, resize))
            else:
                resized_wand = library.MagickTransformImage(new_wand,crop,resize)
        self.sequence.instances = []
        self.wand = resized_wand
@pthimon
Copy link
Author

pthimon commented Jul 14, 2015

In addition, as transform also supports cropping, it is useful to do a MagickResetImagePage for each frame at the same time as the transform:

if self.animation:
        resized_wand = None
        new_wand = library.MagickCoalesceImages(self.wand)
        length = len(self.sequence)
        for i in xrange(length):
            library.MagickSetIteratorIndex(new_wand, i)
            if i:
                tmp_wand = library.MagickTransformImage(new_wand, crop, resize)
                library.MagickResetImagePage(tmp_wand, None)
                library.MagickAddImage(resized_wand, tmp_wand)
            else:
                resized_wand = library.MagickTransformImage(new_wand,crop,resize)
                library.MagickResetImagePage(resized_wand, None)
        self.sequence.instances = []
        self.wand = resized_wand

@emcconville
Copy link
Owner

emcconville commented Jun 11, 2020

Thanks for reporting this, and sorry for the 5 year delay. You are correct with new_wand being reused, and introducing issues with animations + memory leaks. Holding off on paging reset as folks disagree with default behavior, and transform is also being deprecated. In fact, it was removed in ImageMagick-7.

@emcconville emcconville added this to the Wand 0.6.2 milestone Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants