先演示一下:
今天剛寫的,還熱乎著呢,代碼如下:
<?php
Header("Content-type: image/png");
$txt=$_GET[txt]."(刷新我會變色哦)";
$i=strlen($txt);
$width=16*strlen($txt);
$height=42*(int)($width/500+1);
$im = imagecreate($width,$height);
$background_color=imageColorAllocate($im,223,223,223);
$white=imageColorAllocate($im,255,255,255);
$color1=imageColorAllocate($im,255,128,128);
$red=imageColorAllocate($im,255,0,0);
$color3=imageColorAllocate($im,128,64,64);
$yellow=imageColorAllocate($im,255,255,0);
$color4=imageColorAllocate($im,255,128,0);
$color5=imageColorAllocate($im,128,128,0);
$green=imageColorAllocate($im,0,255,0);
$color6=imageColorAllocate($im,0,128,0);
$blue=imageColorAllocate($im,0,0,255);
$pink=imageColorAllocate($im,255,0,128);
$black=imageColorAllocate($im,0,0,0);
$array=array($color1,$red,$color3,$color4,$color5,$green,$color6,$blue,$pink,$black,$white);
$x=1;
$y=40;
$count=1;
for($t=0;$t<$i;$t++)
{
$temp=rand(0,10);
$color=$array[$temp];
if (ord($txt[$t]) >= 128)
{
if($x+32>500)
{
$x=1;
$y=40+$count*41;
$count++;
}
$temp=$txt[$t++].$txt[$t];
$temp=mb_convert_encoding($temp, "UTF-8", "gb2312");
imagettftext($im,24, 0, $x, $y, $color,"tupian/finish/simsun.ttc",$temp);
$x+=32;
}
else
{
if($x+8>500)
{
$x=1;
$y=40+$count*41;
$count++;
}
imagettftext($im,24, 0, $x, $y, $color,"tupian/finish/simsun.ttc",$txt[$t]);
$x+=16;
}
}
ImagePNG($im);
ImageDestroy($im);
?>
使用說明:將上面的代碼保存為1.php!
1、在浏覽器中輸入http://你的網址/1.php?txt=文字 可直接觀看效果
2、在論壇中以這樣的形式發帖:{img}http://你的網址/1.php?txt=文字{/img}(實際用時把大括號換為中括號)
PS:如果你的空間不支持mb_convert_encoding函數,你需要有把gb2312轉為utf-8的函數才能支持中文!