使用PHP从html创建动画gif

使用PHP从html创建动画gif,php,animated-gif,Php,Animated Gif,我需要使用以下简单html创建和保存新的动画gif: <div id="wrap"> <div id="content"> <p>Message here</p> <img src="image.jpg" /> </div> <img src="image.gif" width="709" height="425" /> </div> 留言 代码末尾的gif是一个动画

我需要使用以下简单html创建和保存新的动画gif:

<div id="wrap">
  <div id="content">
    <p>Message here</p>
    <img src="image.jpg" />
  </div>
  <img src="image.gif" width="709" height="425" />
</div>

留言

代码末尾的gif是一个动画gif,我希望能够在上面覆盖文本和另一个jpeg图形,保留gif的动画

第一,这是可能的,第二,如果可能的话,请有人给我指出正确的方向


我猜我可能需要以某种方式合并PHPs imagegif函数???

据我所知,PHP的GD库函数无法生成动画GIF

您必须依赖其他工具,例如ImageMagik的
转换
函数(您可以通过
exec
调用它)

评论后编辑:

如果您只想创建一个非动画gif,那么使用GD库就可以轻松完成该过程

假设您的文本位于一个变量
$txt
,以及两个要堆叠的图像
image1.jpg
image2.gif

最终结果将是

    TEXT
-------------
|           |
|  IMAGE 1  |
|           |
 -----------
-------------
|           |
|  IMAGE 2  |
|           |
 -----------
首先打开两个图像:

$i1 = imagecreatefromjpeg("image1.jpg");
$i2 = imagecreatefromgif("image2.gif");
现在找到这两个图像的大小

$i1_w = imagesx($i1);
$i1_h = imagesy($i1);
$i2_w = imagesx($i2);
$i2_h = imagesy($i2);
您的最终图像将具有

// Add 30px for the text, you can calculate this precisely 
// using imagettfbbox but be sure to use imagettftext 
// instead of imagestring later
$height = $i1_h + $i2_h + 30;
$width = max($i1_w, $i2_w);
现在创建输出图像

$img = imagecreatetruecolor($width, $height);
把课文放在上面

$black = imagecolorallocate($img, 0, 0, 0);
// Instead of using 1 as 2nd parameter you can use a font created 
// with imageloadfont. Also, you may want to calculate text coordinates
// so that it is centered etc.
imagestring($img, 1, 10, 10, $txt, $black);
现在添加图像

imagecopy($img, $img1, ($width-$img1_w)/2, 30, 0, 0, $img1_w, $img1_h);
imagecopy($img, $img2, ($width-$img2_w)/2, 35+$img1_h, 0, 0, $img2_w, $img2_h);
最后,输出gif文件

header('Content-Type: image/gif');
imagegif($img); // Or imagejpeg, imagepng etc.
如果您只想保存图像,而不显示图像,请执行以下操作:

imagegif($img, "output.gif");

据我所知,PHP的GD库函数无法生成动画GIF

您必须依赖其他工具,例如ImageMagik的
转换
函数(您可以通过
exec
调用它)

评论后编辑:

如果您只想创建一个非动画gif,那么使用GD库就可以轻松完成该过程

假设您的文本位于一个变量
$txt
,以及两个要堆叠的图像
image1.jpg
image2.gif

最终结果将是

    TEXT
-------------
|           |
|  IMAGE 1  |
|           |
 -----------
-------------
|           |
|  IMAGE 2  |
|           |
 -----------
首先打开两个图像:

$i1 = imagecreatefromjpeg("image1.jpg");
$i2 = imagecreatefromgif("image2.gif");
现在找到这两个图像的大小

$i1_w = imagesx($i1);
$i1_h = imagesy($i1);
$i2_w = imagesx($i2);
$i2_h = imagesy($i2);
您的最终图像将具有

// Add 30px for the text, you can calculate this precisely 
// using imagettfbbox but be sure to use imagettftext 
// instead of imagestring later
$height = $i1_h + $i2_h + 30;
$width = max($i1_w, $i2_w);
现在创建输出图像

$img = imagecreatetruecolor($width, $height);
把课文放在上面

$black = imagecolorallocate($img, 0, 0, 0);
// Instead of using 1 as 2nd parameter you can use a font created 
// with imageloadfont. Also, you may want to calculate text coordinates
// so that it is centered etc.
imagestring($img, 1, 10, 10, $txt, $black);
现在添加图像

imagecopy($img, $img1, ($width-$img1_w)/2, 30, 0, 0, $img1_w, $img1_h);
imagecopy($img, $img2, ($width-$img2_w)/2, 35+$img1_h, 0, 0, $img2_w, $img2_h);
最后,输出gif文件

header('Content-Type: image/gif');
imagegif($img); // Or imagejpeg, imagepng etc.
如果您只想保存图像,而不显示图像,请执行以下操作:

imagegif($img, "output.gif");

好吧,如果它不再是动画,那也不是世界末日。如果我不给它设置动画,它会更容易吗?好吧,如果它不再设置动画,那就不是世界末日了。如果我不设置动画,会更容易吗??