如果您想创建带有随机文本的图像,这将做到
图像.php
require_once 'text.php';
header("Content-type: image/png");
$string = wordwrap($t[0], 31, "\n", true); //text
$font = 2;
$width = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);
$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);
imagestring ($image,$font,0,0,$string,$black);
imagepng ($image);
imagedestroy($image);
更新代码到您的响应:
如果您想在特定图像上获取随机文本
require_once 'text.php';
header("Content-type: image/png");
$string = wordwrap($t[0], 31, "\n", true); //text
$image = ImageCreateFromJPEG("img_empty.jpg");
//Defining color. Making the color of text as red (#FFF) as 255,000,000
$color = imagecolorallocate($image , 255, 000, 000); //
//put string over image with $color as color
imagestring($image,5,126,22,$string,$color);
imagejpeg($image,NULL,100);
上面的代码将在您指定的图像上放置一个红色随机文本。这对我有用。还可以尝试更改 imagecolorallocate() 函数中定义的颜色。
参考:http ://blog.doh.ms/2008/02/12/adding-text-to-images-in-real-time-with-php/