What is the best way to adjoin images?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Whiteboy

What is the best way to adjoin images?

Post 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 :)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post 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");
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Whiteboy

Post 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.
Whiteboy

Post 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!
Whiteboy

Post 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!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply