Page 1 of 1

What is the best way to adjoin images?

Posted: 2007-01-02T23:04:52-07:00
by Whiteboy
Hi,

I'm generating the following image using an STL list and the writeImages() method in order to create the animation.

Image

I am generating each frame as I go.. then when I'm done generating, writeImages() iterates through the list again to write all of the frames to one image. Is there a way I can have a master Image that I can append images to it as I generate the frames?

I just don't like it that I have to reiterate through the list in order to write the image. I keep on searching for an append() method.. so I can simply do the following pseudo code:

masterImage.adjoin(true);
// a loop that generates each frame goes here
masterImage.append(/* image frame in here */); // I know this method doesn't exist.. just bear with me
// end of loop
masterImage.write("filename.gif");



I feel like because I have to iterate through the list in order to write the image that I'm gaining unwanted execution time.
Any ideas?

(I'm looking for a Magick++ solution not a command-line solution, thanks :)

Posted: 2007-01-03T12:37:08-07:00
by magick
STL is the way to go. You can append images with the appendImages() method. For example,
  • list<Image> imageList;
    readImages( &imageList, srcdir + "test_image_anim.gif" );

    Image appended;

    appendImages( &appended, imageList.begin(), imageList.end() );

    appended.write("appendImages_horizontal_out.gif");

Posted: 2007-01-03T19:08:47-07:00
by anthony
When your animation is finished run it though a "-coalesce -layers optimize" sequence to compess the GIF file down a massive amount. This type of GIF animation will compress extremely well.

Posted: 2007-01-03T22:23:24-07:00
by Whiteboy
Excellent. Thanks for your replies, I'll keep generating the animation the same way I'm doing now with a STL list. And that optimization was awesome. I had a 181x181 animation (similar to the one in the first post) that was reduced from 117K to 16K.

Thanks again.

Posted: 2007-01-03T23:01:59-07:00
by Whiteboy
Oh, and I forgot to ask you. Can I do these optimizations using Magick++ ?

I see that there is a coalesceImages() method but I don't see any method for optimizing layers. I'd like to keep as far away from command-line as possible :) Thanks!

Posted: 2007-01-04T00:00:50-07:00
by Whiteboy
Nevermind, I see that the -layers optimize was simply cropping my frames into little gifs and paging them to the image. I just modified my code to do the following and the image size is just as small (if not smaller) than what was being produced from 'convert -coalesce -layers optimize' and it does it in about 0.1% of the time :)

Thanks again!

Posted: 2007-01-04T16:50:55-07:00
by anthony
Yes that is all it does. GIF animation optimisaions only becomes complex when you need to 'clear' pixels to transparency afterward, or you have color reduction problems. Neither is the case for you so you have it easy.

Just output the changed part with the right virtual canvas or 'page' offset and you will be right.

See IM examples Animation Basics for more details of GIF animation, how it happens and handling it.