使用 PHP 从 html 创建动画 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 函数?
I have the following simple html which I need to use to create and save a new animated 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>
The gif towards the end of the code is an animated gif - I would then like to be able to overlay text and another jpeg graphic over the top of this, retaining the animation of the gif.
Firstly is this possible and secondly could someone please point me in the right direction if it is.
I'm guessing I might need to incorporate PHPs imagegif function somehow??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,PHP的GD库函数无法生成GIF动画。
您将不得不依赖其他工具,例如 ImageMagik 的
convert
函数(您可以通过exec
调用它)。评论后编辑:
如果您只想创建非动画 gif,那么使用 GD 库可以轻松完成该过程。
假设您的文本位于变量
$txt
中,还有两个要堆叠的图像image1.jpg
和image2.gif
。最终结果将如下所示
您首先打开两个图像:
现在找到两个图像的大小。
您的最终图像将具有
现在您创建输出图像
将文本放在顶部
现在添加图像
最后,输出 gif
如果您只想保存图像而不显示它,只需执行以下操作:
As far as I am aware, PHP's GD library function are not able to generate animated GIFs.
You will have to rely on other tools, such as ImageMagik's
convert
function (you can call it throughexec
).EDIT after comment:
If you just want to create a non-animated gif, then the process is easily done with GD libraries.
Say you have your text in a variable
$txt
, and two imagesimage1.jpg
andimage2.gif
that you want to stack.The end result will look like
You would first open the two images:
Now find the size of the two images.
Your final image will have
Now you create your output image
Put the text on top
Now add the images
Finally, output the gif
If you just want to save the image, without showing it just do: