服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

a4745223 发表于 2008-8-31 00:21:35

php图片处理——根据输入合成图片

<P>能够根据自己在浏览器中的参数后输入的文字,实时输出合成相应的文字图片,还可根据自己的设置显示不同颜色,或否显示IP等。用到了php脚本的一些图形处理函数。。。</P>
<P>演示没有自己的网站,就"借用"别人的了。。^_^</P>
<P>&nbsp;</P>
<P>举例演示:</P>
<P>访问http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&amp;line2_color=yellow&amp;bg_color=black&amp;font_color=grey&amp;ipoutput=yes</P>
<P>或贴入图片http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&amp;line2_color=yellow&amp;bg_color=black&amp;font_color=grey&amp;ipoutput=yes&amp;sfld.gif</P>
<P>则相应显示:</P>
<P><A href="http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&amp;line2_color=yellow&amp;bg_color=black&amp;font_color=grey&amp;ipoutput=yes&amp;sfld.gif" target=_blank><IMG src="http://www.dgw.cc/upfile/ck1.php?str=文字标题|文本1|文本2&amp;line2_color=yellow&amp;bg_color=black&amp;font_color=grey&amp;ipoutput=yes&amp;sfld.gif" border=0></A></P>
<P>&nbsp;图片截取:</P>
<P><A href="http://space.hackbase.com/attachments/2008/08/5483026_200808301611341ZrJ0.jpg" target=_blank><IMG src="http://space.hackbase.com/attachments/2008/08/5483026_200808301611341ZrJ0.jpg" border=0></A></P>
<P>输入参数config=help可查看参数的配置情况</P>
<P>&nbsp;</P>
<P>PHP脚本的实现代码如下:</P>
<P><FONT color=#ff0000>&lt;?php<BR>//$font_file = "heiti.ttf";<BR>//$imgWidth = 400;<BR>//$font_size = 14;<BR>//$title_size = 16;<BR>//$line_color="red";<BR>//$line2_color="white";<BR>//$title_color="red";<BR>//$font_color="black";<BR>//$bg_color="white";</FONT></P>
<P><FONT color=#ff0000>if(!($font_file=$_REQUEST)){$font_file = "heiti.ttf";}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //参数设置<BR>if(!($imgWidth=$_REQUEST)){$imgWidth = 400;}<BR>if(!($font_size=$_REQUEST)){$font_size = 14;}<BR>if(!($title_size=$_REQUEST)){$title_size = 16;}<BR>if(!($line_color=$_REQUEST)){$line_color="red";}<BR>if(!($line2_color=$_REQUEST)){$line2_color="white";}<BR>if(!($title_color=$_REQUEST)){$title_color="red";}<BR>if(!($font_color=$_REQUEST)){$font_color="black";}<BR>if(!($bg_color=$_REQUEST)){$bg_color="white";}</FONT></P>
<P><FONT color=#ff0000>if($config=$_REQUEST){<BR>if($config=="help"){<BR>echo "制作者:大鱼,上路,非常大鱼...等,^_^名字多了,其实就是一个人^_^&lt;br&gt;&lt;br&gt;";<BR>echo "默认参数:&lt;br&gt;font_file = \"$font_file\";&nbsp;&nbsp;&nbsp; 字体&lt;br&gt;";<BR>echo "imgWidth = $imgWidth;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 图片宽度&lt;br&gt;";<BR>echo "font_size = $font_size;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 文本字体大小&lt;br&gt;";<BR>echo "title_size = $title_size;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 标题字体大小&lt;br&gt;";<BR>echo "line_color=\"$line_color\";&nbsp;&nbsp;&nbsp; 外框颜色&lt;br&gt;";<BR>echo "line2_color=\"$line2_color\";&nbsp; 内框颜色&lt;br&gt;";<BR>echo "title_color=\"$title_color\";&nbsp; 标题字体颜色&lt;br&gt;";<BR>echo "font_color=\"$font_color\";&nbsp;&nbsp;&nbsp; 文本字体颜色&lt;br&gt;";<BR>echo "bg_color=\"$bg_color\";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 背景颜色&lt;br&gt;";<BR>echo "参数可自行设置,若ipoutput=yes可显示IP";<BR>echo "&lt;br&gt;&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 支持的颜色: white,balck,red,green,blue,grey,yellow";<BR>}<BR>exit;<BR>}</FONT></P>
<P><FONT color=#ff0000>if(!($str=$_REQUEST)){$str = "偶是上路,有事吗?!";}<BR>$strs=explode('|',$str);<BR>$num = count($strs);<BR>$ipoutputyes=0;<BR>if("yes"==$_REQUEST||$ipoutputyes==1){<BR>$ipoutput=1;<BR>$ip = $_SERVER['REMOTE_ADDR'];<BR>$imgHeight = 10+30+$title_size+$num*($font_size+5)+35;}<BR>else{<BR>$imgHeight = 10+30+$title_size+$num*($font_size+5);<BR>}<BR>if(strlen($strs)&gt;18){$strs="标题太长!";}</FONT></P>
<P><FONT color=#ff0000>Header("Content-type: image/PNG");<BR>$authimg = imagecreate($imgWidth,$imgHeight);<BR>$white=imagecolorallocate($authimg,0xFF,0xFF,0xFF);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //颜色定义<BR>$black=imagecolorallocate($authimg,0x00,0x00,0x00);<BR>$red=imagecolorallocate($authimg,0xFF,0x00,0x00);<BR>$green=imagecolorallocate($authimg,0x00,0xFF,0x00);<BR>$blue=imagecolorallocate($authimg,0x00,0x00,0xFF);<BR>$grey=imagecolorallocate($authimg,0x80,0x80,0x80);<BR>$yellow=imagecolorallocate($authimg,0xFF,0xFF,0x00);</FONT></P>
<P><FONT color=#ff0000>imagefilledrectangle($authimg, 0, 0, $imgWidth, $imgHeight, $$bg_color);<BR>imagecolortransparent($authimg, $white);<BR>imagerectangle($authimg, 0, 0, ($imgWidth-1), ($imgHeight-1), $$line_color);<BR>imagerectangle($authimg, 3, 3, ($imgWidth-4), ($imgHeight-4), $$line2_color);</FONT></P>
<P><FONT color=#ff0000>$imgtmid=$imgWidth/2-strlen($strs)*($title_size/2);<BR>ImageTTFText($authimg, $title_size, 0, $imgtmid, 30, $$title_color, $font_file, iconv("GB2312","UTF-8",$strs));</FONT></P>
<P><FONT color=#ff0000>for ($i=1;$i&lt;$num;$i++){<BR>$w1=10;<BR>$h1=40+$title_size+($i-1)*($font_size+5);<BR>ImageTTFText($authimg, $font_size, 0, $w1, $h1, $$font_color, $font_file, iconv("GB2312","UTF-8",$strs[$i]));<BR>}<BR>if($ipoutput==1){<BR>$ipstr="您的IP:".$ip;<BR>imageline($authimg,0,($imgHeight-35),$imgWidth,($imgHeight-35),$$line_color);<BR>ImageTTFText($authimg, 15, 0, 10, ($imgHeight-15), $$title_color, $font_file, iconv("GB2312","UTF-8",$ipstr));<BR>}<BR>ImagePNG($authimg);<BR>ImageDestroy($authimg);<BR>?&gt;</FONT></P>
<P>其中$font_file="heiti.ttf"字体文件heiti.ttf等需要自己上传配置。。。</P>

chewang 发表于 2006-6-12 22:57:05

re:php图片处理——根据输入合成图片

<P>谢谢海哥的答复,一直困扰我的问题终于解决了!!!</P>
<P>&nbsp;</P>
页: [1]
查看完整版本: php图片处理——根据输入合成图片