ÓÃPHP²úÉú¶¯Ì¬µÄÓ°Ïñͼ

5年以前  |  阅读数:417 次  |  编程语言:PHP 

ºÜ¶aÈ˲»Á˽a PHP ¿ÉÒÔ²uÉuÇHTMLµÄ×ÊÁÏ.ÕaÊǶԲuÉuÓ°Ïñͼdz£ÓÐÓõÄ.¿ÉÒÔ´Ó database ²uÉuÒ»¸o¼oµ¥µÄ¹a¸aeºaͼ»o¸u¼oµ¥Ö»²uÉuÒ»¸oͼÐΰ´Å¥ .

ÎÒÓà TTF ×ÖÐÍÔÚÒÔϵÄ*¶ÀýÖÐ
ÎÒͨ³£È¡Ãu×÷ 'button.php3':

#######################################################
-----button.php3------
<?
Header("Content-type: image/gif");
if(!isset($s)) $s=11;
$size = imagettfbbox($s,0,"fonts/TIMES.TTF",$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im = imagecreate($dx+$xpad,$dy+$ypad);
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "fonts/TIMES.TTF", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "fonts/TIMES.TTF", $text);
ImageGif($im);
ImageDestroy($im);
?>
#######################################################
ºÜÖØÒªÒ»µaÊÇÄa²»ÄÜÔÚÕaµµ°¸ÖÐ*ÅÈκÎHTML tags.Ò²²»ÄÜÓпհ×ÐÐÔÚ <?ºÍ ?> tag ֮ǰ»oÖ®aa. Èç¹uÄaÓÃÕa¶ÎScriptaa¿´µ½Ò»¸o²»ÍeÕuµÄÓ°Ïñ, ±iʾÄa¿ÉÄÜÔÚPHP±eÇ(C)ÒÔÍaÎo´oÁË×ÖÔª.

ÒÔÉ쵀 script ¿ÉÒÔÓÉ´ËÓi*¨ÔÚÍøÒ³ÖнгoÀ´:

#######################################################
----test.php-----

New Page 1 #######################################################

test.php½a¹u»aÏñÕaÑu: .

's' ²ÎÊýÊÇÉe¶¨×ÖÐÍ´oС .

ÕaÊǵ± s=18 ʱ:

×¢I:
×ÖÐÍÂ*¾¶ "/fonts/TIMES.TTF" ¿ÉÓÉwindows/fontsĿ¼ÏÂÈ¡µÃ TIMS.TTF ×ÖÐ͵µ Copy ÖÁÄaÍøÕ¾µÄĿ¼ fontsϼ´¿É²aÊÔ ÖÁi¶ÖÐÎĵıiÏÖ Éдý¸÷λÍøÓÑÌa¹(C)ÐĵÃ

×¢Òa ÎÒÏÈ»­ÁËÒ»¸oºÚÉ«½¿eÇøÔÙÓð×ɫλÒƲuÉu 3D Ч¹u.Ò²ÚiL¨ÔÚdzɫ±³¾°Öп´³oÀ´ µ«Äa¿ÉÒ԰ѱ³¾°É«¸ÄΪÉiÉ«¿´¿´´ËЧ¹u. ×ÖÐÍÒ²×oÁËͬÑuЧ¹u±iÏÖÁ¢Ìa¸Ð.

ÄaÒªÏÈȶ¨ÄaµÄ°²×° PHP ʱÓÐÉe¶¨Ö§Ô® GD ºÍ TTF. ¿É²Î¿¼ PHP FAQ . ÎÒ½¨Òe¿ÉÒÔ copy libgd.a µ½ /usr/local/lib ºÍ gd.h Ïa¹Øµµ°¸µ½ /usr/local/include È»aa
'make install' for FreeTTF library.

¿ÉÒÔÔÚÕahttp://rover.wiesbaden.netsurf.de/~kikita/ ÕÒµ½iÎhttf ×ÖÐÍŶ!

×¢:

ÒÔϵÄԭʼÂe¸Ä½øÁËÉÏÃaeµÄÛÍ?¿É¶aÐÐÎÄ×ÖÏÔʾ:
#######################################################
--------------button.php-----------------
<?

Header("Content-type: image/jpeg");
if(!isset($bgred)) $bgred=0;
if(!isset($bggreen)) $bggreen=51;
if(!isset($bgblue)) $bgblue=153;
if(!isset($chred)) $chred=255;
if(!isset($chgreen)) $chgreen=255;
if(!isset($chblue)) $chblue=255;
if(!isset($shadow)) $shadow="yes";
if(!isset($wrappos)) $wrappos=20;
if(!isset($crop)) $crop=2.2;
if(!isset($jpegquality)) $jpegquality=80;
if(!isset($s)) $s=11;
$savetext=$text;
$text=wordwrap($text,$wrappos," ",0);
if (!isset($font)) $fontname="/www/ttfonts/arialbd.ttf";
else
$fontname="/www/ttfonts/".$font.".ttf";
$size = imagettfbbox($s,0,$fontname,$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$upper=abs($size[5]);
$under=$size[1];
$th=$upper-$under;
$xpad=9;
if (substr_count($text,chr(13))>=1)
{
$mult=(substr_count($text,chr(13)));
$ypad=($mult$crop$s)+$s;
}
else $ypad=($crop-2)*$s;
$im = imagecreate($dx+$xpad,$th+$ypad);
$color = ImageColorAllocate($im, $bgred,$bggreen,$bgblue);
$black = ImageColorAllocate($im, 0,0,0);
$fontcolor = ImageColorAllocate($im, $chred,$chgreen,$chblue);
ImageRectangle($im,0,0,$dx+$xpad-1,$th+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$th+$ypad,$white);
if ($shadow=="yes")
ImageTTFText($im, $s, 0, (int)($xpad/2)-2+1, $th+2+(int)($ypad/2)-3, $black, $fontname, $text);
ImageTTFText($im, $s, 0, (int)($xpad/2)-2, $th+2+(int)($ypad/2)-1-3, $fontcolor, $fontname, $text);
Imagejpeg($im,"",$jpegquality);
ImageDestroy($im);

?>
#######################################################
Õa¿ÉÒÔÏÂÃaeÕa¸o form À´²uÉu:
#######################################################
----------test.php--------------------

New Page 1

ÎÄ×Ö

´oС

¶Ï¾aµÄλÖÃ(wrap break position)

±³¾°ÑÕÉ«

ºiÉ« ÂÌÉ« À¶É«

×ÖÔªÑÕÉ«

ºiÉ« ÂÌÉ« À¶É«

×ÖÐÍ

ÒoÓ° ÊÇ

Crop size

Jpeg Æ*ÖÊ (0-100)

#######################################################

»oÊÇÖ±½ÓÏñÉÏÀýÒ»Ñuºo½Ð:

#######################################################
----test.php-----

New Page 1
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例