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

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
garyb
Posts: 11
Joined: 2012-03-07T14:00:46-07:00
Authentication code: 8675308

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

Post 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!
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

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

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
garyb
Posts: 11
Joined: 2012-03-07T14:00:46-07:00
Authentication code: 8675308

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

Post 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. :(
garyb
Posts: 11
Joined: 2012-03-07T14:00:46-07:00
Authentication code: 8675308

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

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

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

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
garyb
Posts: 11
Joined: 2012-03-07T14:00:46-07:00
Authentication code: 8675308

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

Post by garyb »

Cool, will do, thanks for all the help.
Post Reply