Question

I have next code for resizing images:

Image image;
image.read( imagePath.toStdString() );
Geometry newSize = Geometry(m_newSize.width(), m_newSize.height());
newSize.aspect(true);
image.resize(newSize);
image.write(newImagePath.toStdString());

This code work fine for non-gif files. For gif files I loss animation: Before resizing gif file

After resizng

How to resize gif files without animation loss?

Was it helpful?

Solution

I found a solution! Thank you MofX for right direction!

   Geometry newSize = Geometry(m_newSize.width(), m_newSize.height());
   newSize.aspect(true); 
   list<Image> frames;
   readImages(&frames, imagePath.toStdString());
   for (auto& image : frames)
        image.resize(newSize);
   writeImages(frames.begin(), frames.end(), newImagePath.toStdString());

OTHER TIPS

You have to use readImages and animateImages to read all frames of the animation into an image list and to add them to an animation.

Look at this example at http://www.imagemagick.org/Magick++/STL.html:

#include <list> 
#include <Magick++.h> 
using namespace std; 
using namespace Magick;

int main(int /*argc*/,char **/*argv*/) 
{ 
    list<Image> imageList; 
    readImages( &imageList, "test_image_anim.gif" );

    Image appended; 
    appendImages( &appended, imageList.begin(), imageList.end() ); 
    appended.write( "appended_image.miff" ); 
    return 0; 
}

The only problem is, that the documentation says, that animatImages works only under X11

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top