国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

用PHP產生動態的影像圖

瀏覽:37日期:2024-01-20 16:41:54
很多人不了解;;PHP 可以產生非HTML的資料.這是對產生影像圖非常有用的.可以從 database 產生一個簡單的廣告橫圖或更簡單只產生一個圖形按鈕 . 我用 TTF 字型在以下的范例中;;我通常取名作 '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); ?> ####################################################### 很重要一點是你不能在這檔案中放任何HTML tags.也不能有空白行在 <?和 ?> tag 之前或之後. 如果你用這段Script後看到一個不完整的影像, 表示你可能在PHP標簽以外誤打了字元. 以上的 script 可以由此語法在網頁中叫出來: <IMG SRC="button.php3?s=36&text=PHP+is+Cool">;;####################################################### ----test.php-----;;<html> <head> <META HTTP-EQUIV="content-type" CONTENT="text/html; charset=gb2312"> <title>New Page 1</title> </head> <body>;;<IMG SRC="button.php3?s=36&text=PHP+is+Cool">;;</body> </html> #######################################################;;test.php結果會像這樣: . 's' 參數是設定字型大小 .;;這是當 s=18 時:;;注I: 字型路徑 "/fonts/TIMES.TTF" 可由windows/fonts目錄下取得 TIMS.TTF 字型檔 Copy 至你網站的目錄 fonts下即可測試 至於中文的表現 尚待各位網友提供心得;;注意 我先畫了一個黑色方塊區再用白色位移產生 3D 效果.也陬L法在淺色背景中看出來 但你可以把背景色改為深色看看此效果. 字型也做了同樣效果表現立體感.;;你要先確定你的安裝 PHP 時有設定支援;;GD 和 TTF. 可參考;;PHP FAQ . 我建議可以 copy libgd.a 到;;/usr/local/lib 和 gd*.h 相關檔案到;;/usr/local/include 然後;;;'make install' for FreeTTF library.;;可以在這http://rover.wiesbaden.netsurf.de/~kikita/ 找到釵httf 字型哦! 注: 以下的原始碼改進了上面的弁?可多行文字顯示: ####################################################### --------------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); ?> ####################################################### 這可以下面這個 form 來產生: ####################################################### ----------test.php-------------------- <html> <head> <title>New Page 1</title> </head> <body> <form method="POST" action="button.php"> <p>文字<input type="text" name="text" size="60"></p> <p>大小<input type="text" name="s" size="6" value="14"></p> <p>斷句的位置(wrap break position) <input type="text" name="wrappos" size="3" value="20"></p> <p>背景顏色</p> <p>紅色<input type="text" name="bgred" size="6" value="0">&nbsp;&nbsp;&nbsp;;;;;;;;綠色<input type="text" name="bggreen" size="8" value="51">&nbsp;&nbsp;&nbsp;;;;;;;;;藍色<input type="text" name="bgblue" size="7" value="153"></p> <p>字元顏色</p> <p>紅色 <input type="text" name="chred" size="6" value="255">&nbsp;&nbsp;&nbsp; ;;;;;;綠色 <input type="text" name="chgreen" size="8" value="255">&nbsp;&nbsp;&nbsp;;;;;;;;藍色 <input type="text" name="chblue" size="7" value="255"></p> <p>字型 <input type="text" name="font" size="20" value="arialbd"></p> <p>陰影 <input type="radio" value="yes" checked name="shadow">是;;;;;;;;;<input type="radio" name="shadow" value="no">否</p> <p>Crop size <input type="text" name="crop" size="20" value="2.2"></p> <p>Jpeg 品質 (0-100) <input type="text" name="jpegquality" size="20" value="80"></p> <p><input type="submit" value="Submit" name="B1"> ;;;;;;<input type="reset" value="Reset" name="B2"></p> </form> </body> </html> ####################################################### 或是直接像上例一樣呼叫:;;####################################################### ----test.php-----;;<html> <head> <title>New Page 1</title> </head> <body>;;<IMG SRC="button.php?s=36&text=PHP+is+Cool">;;</body> </html>;
標簽: PHP
主站蜘蛛池模板: 2020国产微拍精品一区二区 | 香蕉在线观看999 | 中文字幕乱码在线观看 | 欧美一区二区三区在观看 | 黄色影院在线 | 亚洲美女视频在线观看 | 国产手机精品一区二区 | 国产成人亚洲精品久久 | 久久精品高清 | 香蕉网影院在线观看免费 | 曰本人做爰大片免费观看一 | 色老头久久久久 | 久久精品国产亚洲综合色 | 欧美日韩高清性色生活片 | 好看毛片| www.亚洲在线 | 国产精品男人的天堂 | 国产真实乱子伦精品 | 国产亚洲一区二区手机在线观看 | 久久亚洲精品tv | 美女舒服好紧太爽了视频 | 最爽的乱淫片免费 | 欧美成人h | 扒开双腿猛进入爽爽在线观看 | 免费看男女做好爽好硬视频 | 欧美一级毛片免费播放器 | 国产在线激情视频 | 五月激激激综合网色播免费 | 久久久久久久久久久久福利 | 一级做a爱视频 | 国产91丝袜在线播放九色 | 天堂色视频 | 国产精品欧美一区二区 | 在线观看一区 | 久久久久依人综合影院 | 爽爽视频在线观看 | 欧美国产永久免费看片 | 欧美性xxxx18 | 大陆60老妇xxxxhd | 九九九九九九精品免费 | 性欧美视频a毛片在线播放 性欧美一级 |