Strange behaviour of MagickAddImage

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
aditan22

Strange behaviour of MagickAddImage

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

Post 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);
}
aditan22

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