Page 1 of 1

Strange behaviour of MagickAddImage

Posted: 2007-01-24T01:23:59-07:00
by aditan22
Hello,

I found a problem when using MagickAddImage, here is my code:

Code: Select all

<?php
$dst=NewMagickWand();
MagickNewImage($dst, 200, 200);

$src2=NewMagickWand();
MagickReadImage($src2,"src2.gif");

MagickSetImageIndex($src2,0);
MagickCompositeImage($dst,$src2,MW_OverCompositeOp,0,0);

MagickSetImageDelay($dst,200);
$numimgs=MagickGetNumberImages($src2);
for($i=1;$i<$numimgs;$i++) {
  MagickSetImageIndex($src2,$i);
  MagickAddImage($dst,$src2);
}

MagickSetFormat($dst,"GIF");
MagickWriteImages($dst,"dst.gif",true);
echo 'DONE!!!';
?>
And src2.gif is:
Image

After running the script, the result (dst.gif) is:
Image

As you can see, the MagickAddImage seems to add the image in reverse order, how to make it to add image in appropriate order? (I cannot reverse the logic of the codes because I need to compose the first frame of src2.gif to new image).

Thanks in advance.

Posted: 2007-01-24T10:08:25-07:00
by magick
We're not sure what you're trying to do but give this a try:

Code: Select all

MagickResetIterator($dst);
MagickResetIterator($src2);
while (MagickNextImage($src2))
{
  MagickAddImage($dst,$src2);
}

Posted: 2007-01-24T21:42:34-07:00
by aditan22
Wonderful! I use MagickResetIterator before the 'for' statement:

Code: Select all

MagickResetIterator($dst);   //only need to reset the destination img
for($i=1;$i<$numimgs;$i++) 
And it works! :) thanks again!