【发布时间】:2010-10-17 07:27:07
【问题描述】:
有没有办法将文本放在 png 上,然后将其与 jpg / gif 图像合并?
【问题讨论】:
-
你能详细说明你的问题吗?将 png 与 jpg/gif 图像合并是什么意思?
有没有办法将文本放在 png 上,然后将其与 jpg / gif 图像合并?
【问题讨论】:
您可以使用 ttf 或 type1 字体使用 gd 在图像中或图像上绘制任何文本(如果它在 php 中的 gd 中启用)。
【讨论】:
您没有说您使用的是什么语言,但Imagemagick 有几种不同语言的 API (http://www.imagemagick.org/script/api.php)。
【讨论】:
这就是我的做法。
/* load the image */
$im = imagecreatefrompng("image.png");
/* black for the text */
$black = imagecolorallocate($im, 0, 0, 0);
/* put the text on the image */
imagettftext($im, 12, 0, 0, 0, $black, "arial.ttf", "Hello World");
/* load the jpg */
$jpeg = imagecreatefromjpeg("image.jpeg");
/* put the png onto the jpeg */
/* you can get the height and width with getimagesize() */
imagecopyresampled($jpeg,$im, 0, 0, 0, 0, $jpeg_width, $jpeg_height, $im_width, $im_height);
/* save the image */
imagejpeg($jpeg, "result.jpeg", 100);
不过,这是一个非常简单的例子。
【讨论】: