色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

用PHP產生動態的影像圖

瀏覽:49日期: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
主站蜘蛛池模板: 国产欧美曰韩一区二区三区 | 另类专区欧美 | 失禁h啪肉尿出来高h | 在线播放 亚洲 | 欧美久久久久 | 精品久久久久久无码中文字幕 | 国产日韩欧美网站 | 亚洲精品在线免费看 | 又黄又刺激下面流水的视频 | 国产乱子精品免费视观看片 | 中文字幕日韩精品有码视频 | 国产免费影院 | 女人毛片a毛片久久人人 | 在线观看国内自拍 | 国产孕妇做受视频在线观看 | 中文字幕亚洲综合久久男男 | 久久久久久久久久综合情日本 | 91视频国产一区 | 婷婷的久久五月综合先锋影音 | 毛片图片 | 热伊人99re久久精品最新地 | 久久综合久久美利坚合众国 | 香蕉97碰碰视频免费 | 欧美一级二级片 | 5x社区直接进入一区二区三区 | 欧美日韩精品乱国产538 | 欧美一级黄 | 久久国产精品高清一区二区三区 | 久久精品免费观看视频 | 九九视频免费观看 | 国产精品18久久久久网站 | 九九精彩视频在线观看视频 | 亚洲综合综合在线 | 国产亚洲精品aaa大片 | 性色aⅴ在线观看swag | 香蕉成人国产精品免费看网站 | 国产欧美一区二区三区免费 | 三级黄色高清视频 | 国产精品亚洲第一区二区三区 | xxx国产hd | 亚洲 欧美 日韩 丝袜 另类 |