3

有没有办法将文本放在 png 上,然后将其与 jpg / gif 图像合并?

4

3 回答 3

3

您可以使用 ttf 或 type1 字体使用 gd 在图像中或图像上绘制任何文本(如果它在 php 中的 gd 中启用)。

http://hr.php.net/manual/en/image.examples-watermark.php

于 2009-04-03T08:08:07.110 回答
1

这就是我的做法。

/* 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);

这是一个非常简单的例子。

于 2009-04-03T09:20:13.083 回答
0

你没有说你使用的是什么语言,但Imagemagick有几种不同语言的 API ( http://www.imagemagick.org/script/api.php )。

于 2009-04-03T08:16:48.213 回答