Page 1 of 1

MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T11:14:25-07:00
by garyb
Hi, I'm trying to use the MagickWand API to create a single loop animated GIF... a super easy/simple test, but it seems that MagickSetOption(wand, "loop", "1") is ignored. :( I'm using ImageMagick 6.6.9-7 2011-05-02 Q8

Could someone pls tell me what I'm doing wrong?

Code: Select all

MagickWandGenesis();
MagickWand *wand = NewMagickWand();
MagickSetFormat(wand, "gif");

// create img1, 2, 3

MagickSetImageDelay(img1, 10);
MagickAddImage(wand, img1);
DestroyMagickWand(img1);

MagickSetImageDelay(img2, 10);
MagickAddImage(wand, img2);
DestroyMagickWand(img2);

MagickSetImageDelay(img3, 10);
MagickAddImage(wand, img3);
DestroyMagickWand(img3);

MagickSetOption(wand, "loop", "1");
//MagickSetImageIterations(wand, 1); // also tried this with no luck
//Edit: also tried MagickSetImageProperty(wand, "loop", "1");

// save/preview gif...

MagickWandTerminus();
I would expect it to just loop once, but it's looping endlessly.

Thanks!

Re: MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T17:31:19-07:00
by el_supremo
I used the command line to try to set loop to one in the "bunny" animation and it doesn't work either. I don't know if that is just the player program ignoring the setting or whether IM isn't actually doing anything.

Pete

Re: MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T18:58:39-07:00
by garyb
el_supremo wrote:I used the command line to try to set loop to one in the "bunny" animation and it doesn't work either. I don't know if that is just the player program ignoring the setting or whether IM isn't actually doing anything.

Pete
Yeah there *has* to be something I'm overlooking here... I refuse to believe IM can do all this stuff but not set a loop limit on a GIF. :) I tried dragging the GIF into a few different web browsers, sure enough just keeps looping. So I'm guessing it's something to do w/ IM. :(

Re: MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T20:30:45-07:00
by garyb
Okay I got it... I did this inside my for loop, immediately after calling MAgickAddImage on every image and it worked. Not sure if that's necessary but it seems to do the trick and I'm not messing with it! :)

Code: Select all

for(...) {
    MagickWand *wand = NewMagickWand();
    // read image etc.
    MagickAddImage(mainWand, wand);
    MagickSetImageProperty(mainWand, "loop", "1");
    DestroyMagickWand(wand);
}

Re: MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T22:17:59-07:00
by anthony
The setting must be on at least the very first frame! Though applying it to every frame works.

Note when using MagickAddImage. It is a good idea to ensure that you have set what end the image should be added to. We had a case recently where second image gets added at the end, but the third gets added to the front!
I am working to dix this, what this discussion forum!

this is a code example with comment

Code: Select all

    MagickSetLastIterator(red);
    MagickAddImage(red,rose);
    rose = DestroyMagickWand(rose);  /* finished with 'rose' wand */
    /* NOTE ABOUT MagickAddImage()
     * Always set the first/last image in the destination wand so that
     * IM knows if you want to prepend/append the images into that wands
     * image list.
     *
     * Setting a specific index always 'inserts' before that image.
     */
On a related issue...

Code: Select all

   /* append all images together to create the output wand */
    MagickSetFirstIterator(red);
    output = MagickAppendImages(red,MagickFalse);
    red = DestroyMagickWand(red);  /* finished with 'red' wand */
    /* NOTE ABOUT MagickAppendImages()
     * It is important to either set first or reset the iterator before
     * appending images, as only images from current image onward are
     * appended together.
     *
     * Also note how a new wand is created by this operation!
     */
I don't know why it it was designed to work this way, but that is the way it works.

Re: MagickSetOption(wand, "loop", "1") has no effect

Posted: 2012-03-08T22:34:09-07:00
by garyb
Cool, will do, thanks for all the help.