GD库创建带有动态文本的图像 [英] GD library create image with dynamic text on it
本文介绍了GD库创建带有动态文本的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将通过sql select动态生成的文本放在使用GD库创建的图像上.我正在使用它来创建图像并在其上放置一些文本,但是我想将变量$ users与sql select数据一起放置到图像中:
I want to place text generated dynamically from a sql select, on an image created with GD library. I'm using this to create the image and place some text on it, but I want to place the variable $users with the sql select data into the image:
$query = "SELECT id, name FROM users WHERE .... ORDER BY id DESC";
while ($line = mysql_fetch_assoc($query)) {
$users .= "<img src='https://www.example.com/" . $line['id'] . "/photo'/> " . $line['name'] . "<br />";
}
function create_image(){
$im = @imagecreate(550, 600)or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
imagestring($im, 1, 5, 10, $users);
imagestring($im, 2, 5, 50, "Text 2", $red);
imagepng($im,"image.png");
imagedestroy($im);
}
create_image();
print "<img src=image.png?".date("U").">";
$ user变量中的文本不显示,该怎么办?
The text in the $user variable not appear, how can I do this?
谢谢
推荐答案
以下是在png图像上绘制文本的示例:
Here is an example how to draw text on png image:
$img = imagecreatefrompng($image_path); //$image_path -> on which text to be drawn
@imagealphablending($img, true);
@imagesavealpha($img, true);
$textColor = imagecolorallocate($img, 100, 100, 98);
$font = '../fonts/Arial.ttf';
imagettftext($img, 18, 0, 140, 285,$textColor,$font, $name); // $name -> dynamic text to be drawn on image
$path = "path where you want to save created image";
$image = imagejpeg($img, $path);
imagedestroy($img);
完成..
这篇关于GD库创建带有动态文本的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文