能够根据自己在浏览器中的参数后输入的文字,实时输出合成相应的文字图片,还可根据自己的设置显示不同颜色,或否显示IP等。用到了php脚本的一些图形处理函数。。。
演示没有自己的网站,就"借用"别人的了。。^_^
举例演示:
访问http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&line2_color=yellow&bg_color=black&font_color=grey&ipoutput=yes
或贴入图片http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&line2_color=yellow&bg_color=black&font_color=grey&ipoutput=yes&sfld.gif
则相应显示:

图片截取:

输入参数config=help可查看参数的配置情况
PHP脚本的实现代码如下:
<?php //$font_file = "heiti.ttf"; //$imgWidth = 400; //$font_size = 14; //$title_size = 16; //$line_color="red"; //$line2_color="white"; //$title_color="red"; //$font_color="black"; //$bg_color="white";
if(!($font_file=$_REQUEST[font_file])){$font_file = "heiti.ttf";} //参数设置 if(!($imgWidth=$_REQUEST[imgwidth])){$imgWidth = 400;} if(!($font_size=$_REQUEST[font_size])){$font_size = 14;} if(!($title_size=$_REQUEST[title_size])){$title_size = 16;} if(!($line_color=$_REQUEST[line_color])){$line_color="red";} if(!($line2_color=$_REQUEST[line2_color])){$line2_color="white";} if(!($title_color=$_REQUEST[title_color])){$title_color="red";} if(!($font_color=$_REQUEST[font_color])){$font_color="black";} if(!($bg_color=$_REQUEST[bg_color])){$bg_color="white";}
if($config=$_REQUEST[config]){ if($config=="help"){ echo "制作者:大鱼,上路,非常大鱼...等,^_^名字多了,其实就是一个人^_^<br><br>"; echo "默认参数:<br>font_file = \"$font_file\"; 字体<br>"; echo "imgWidth = $imgWidth; 图片宽度<br>"; echo "font_size = $font_size; 文本字体大小<br>"; echo "title_size = $title_size; 标题字体大小<br>"; echo "line_color=\"$line_color\"; 外框颜色<br>"; echo "line2_color=\"$line2_color\"; 内框颜色<br>"; echo "title_color=\"$title_color\"; 标题字体颜色<br>"; echo "font_color=\"$font_color\"; 文本字体颜色<br>"; echo "bg_color=\"$bg_color\"; 背景颜色<br>"; echo "参数可自行设置,若ipoutput=yes可显示IP"; echo "<br><br> 支持的颜色: white,balck,red,green,blue,grey,yellow"; } exit; }
if(!($str=$_REQUEST[str])){$str = "偶是上路,有事吗?!";} $strs=explode('|',$str); $num = count($strs); $ipoutputyes=0; if("yes"==$_REQUEST[ipoutput]||$ipoutputyes==1){ $ipoutput=1; $ip = $_SERVER['REMOTE_ADDR']; $imgHeight = 10+30+$title_size+$num*($font_size+5)+35;} else{ $imgHeight = 10+30+$title_size+$num*($font_size+5); } if(strlen($strs[0])>18){$strs[0]="标题太长!";}
Header("Content-type: image/PNG"); $authimg = imagecreate($imgWidth,$imgHeight); $white=imagecolorallocate($authimg,0xFF,0xFF,0xFF); //颜色定义 $black=imagecolorallocate($authimg,0x00,0x00,0x00); $red=imagecolorallocate($authimg,0xFF,0x00,0x00); $green=imagecolorallocate($authimg,0x00,0xFF,0x00); $blue=imagecolorallocate($authimg,0x00,0x00,0xFF); $grey=imagecolorallocate($authimg,0x80,0x80,0x80); $yellow=imagecolorallocate($authimg,0xFF,0xFF,0x00);
imagefilledrectangle($authimg, 0, 0, $imgWidth, $imgHeight, $$bg_color); imagecolortransparent($authimg, $white); imagerectangle($authimg, 0, 0, ($imgWidth-1), ($imgHeight-1), $$line_color); imagerectangle($authimg, 3, 3, ($imgWidth-4), ($imgHeight-4), $$line2_color);
$imgtmid=$imgWidth/2-strlen($strs[0])*($title_size/2); ImageTTFText($authimg, $title_size, 0, $imgtmid, 30, $$title_color, $font_file, iconv("GB2312","UTF-8",$strs[0]));
for ($i=1;$i<$num;$i++){ $w1=10; $h1=40+$title_size+($i-1)*($font_size+5); ImageTTFText($authimg, $font_size, 0, $w1, $h1, $$font_color, $font_file, iconv("GB2312","UTF-8",$strs[$i])); } if($ipoutput==1){ $ipstr="您的IP:".$ip; imageline($authimg,0,($imgHeight-35),$imgWidth,($imgHeight-35),$$line_color); ImageTTFText($authimg, 15, 0, 10, ($imgHeight-15), $$title_color, $font_file, iconv("GB2312","UTF-8",$ipstr)); } ImagePNG($authimg); ImageDestroy($authimg); ?>
其中$font_file="heiti.ttf"字体文件heiti.ttf等需要自己上传配置。。。 |