Page 1 of 1

Creating animated GIFs using Magick++/MagickCore APIs

Posted: 2010-03-10T01:08:17-07:00
by abhivg
Hi,

I want to create an animated gif from some in memory data. I am trying to implement this in a VC++ 2005.

I am able to compile the solution provided with the IM Windows release and execute the IMDisplay utility for reading image files.
I have prepared a test solution in which I wrote similar code as the IMDisplay utility to read image files. This is working fine.
Now I want to write data into multiple frames in memory and then write those frames to a single animated gif file. I am not sure of how to go about this.

Most of the documentation is related to the command line utilities. I went through the documentation for Magick++ briefly. I am aware that I can write to gif file by using Image::write(filename). However this creates a non-animated gif file. I could not find any API which helps create an animated GIF file with multiple frames.
Can someone point me out the appropriate Magick++ API which I should use to create an animated gif file?

I went through the documentation for MagickCore too and there a few APIs, viz. NewImageList, AppendImageToList. Are these what I should use for my problem? It would help if someone could point me to some sample code available. I would prefer to use the Magick++ api, though.

thanks in advance,
Abhi

Re: Creating animated GIFs using Magick++/MagickCore APIs

Posted: 2010-03-10T02:00:47-07:00
by abhivg
Got it, following code worked for me:

Image img1( "100x100", "white" );
img1.pixelColor( 49, 49, "red" );
frames.push_back(img1);

Image img2( "100x100", "red" );
img2.pixelColor( 49, 49, "white" );
frames.push_back(img2);

img1.animationDelay(2000);
img2.animationDelay(2000);*/

Magick::writeImages(frames.begin(), frames.end(), "f:\\2.gif");

Re: Creating animated GIFs using Magick++/MagickCore APIs

Posted: 2010-08-27T21:09:50-07:00
by anotherprogrammer123
Thanks. Took me a while to find this by searching.

If you are trying to write multi-page TIFF files, just do this:

Code: Select all

vector<Magick::Image> frames;
Magick::Image img1("D:/img.bmp"), img2 ("D:/leaves.jpg");
img1.compressType(MagickLib::JPEGCompression); img1.quality(20); //set JPEG compression at 20%
img2.compressType(MagickLib::JPEGCompression); img2.quality(20); //set JPEG compression at 20%

//add the images into the STL container
frames.push_back(img1); frames.push_back(img2);
Magick::writeImages(frames.begin(), frames.end(), "D:/multi.tif");