php imagecopy不使用gif图像

php imagecopy不使用gif图像,php,animated-gif,Php,Animated Gif,我正在使用此代码给图像加上水印,然后将其保存为带水印。当我试图给gif图像加水印时,问题是我只能得到gif图像的第一帧 imagecopy( // source $main_image, // destination $logoImage, // destination x and y $imageWidth-$logoWidth, $imageHeight-$logoHeight, // source x and y 0, 0, // wi

我正在使用此代码给图像加上水印,然后将其保存为带水印。当我试图给gif图像加水印时,问题是我只能得到gif图像的第一帧

imagecopy(
   // source
   $main_image,
   // destination
   $logoImage,
   // destination x and y
   $imageWidth-$logoWidth, $imageHeight-$logoHeight,
   // source x and y
   0, 0,
   // width and height of the area of the source to copy
   $logoWidth, $logoHeight);
    if($type == "png"){imagepng($main_image, $new_path);}
    if($type == "jpeg"){imagejpeg($main_image, $new_path);}
    if($type == "gif"){imagegif($main_image, $new_path);}

如何解决此问题?

PHP中的
image*
函数使用GD库。虽然PHP手册中没有说明,但GD库不支持GIF动画(尽管网站上有很多评论提到它)。目前,该网站也无法进行进一步确认

或者,如果可用,可以使用调用
convert
应用程序渲染水印+动画服务器端():


与PHP捆绑的GD库不支持动画GIF。但ImageMagick支持:@arxanas您想要最佳答案吗?请注意,ImageMagick在处理动画GIF时会消耗大量资源,因为它需要拆分帧,然后处理每个帧。
$animated_gif = "source.gif";
$gif_with_watermark = "destination.gif";
$watermark = "watermark.png";

$cmd = 'convert '
       . escapeshellarg($animated_gif)
       . ' -coalesce -gravity South -geometry +0+0 null: '
       . escapeshellarg($watermark)
       . ' -layers composite -layers optimize '
       . escapeshellarg($gif_with_watermark);
exec($cmd);