,如果你想創建一個隨機文本的圖像,這將做到這一點
image.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/
您是否試圖製作一個驗證碼?另外,你對「隨機圖像」意味着什麼? – Thorbear 2012-08-03 12:38:51
不是驗證碼。 想要在固定圖像背景上隨機播放隨機圖像:) – Aviral 2012-08-03 16:23:52