$width = 200; $height =300; $img = imagecreatetruecolor($width,$height) or die("不支援gd影像處理"); $line_color = imagecolorallocate($img, 255, 255, 255); $font_type ="c://windows//fonts//simli.ttf"; //擷取truetype字型,採用隸書字型 //“西遊記”3個字16進位字元 $cn_char1 = chr(0xe8).chr(0xa5).chr(0xbf); $cn_char2 = chr(0xe6).chr(0xb8).chr(0xb8); $cn_char3 = chr(0xe8).chr(0xae).chr(0xb0); //“吳承恩著”4個字16進位字元 $cn_str = chr(0xe5).chr(0x90).chr(0xb4).chr(0xe6).chr(0x89).chr(0xbf).chr(0xe6).chr(0x81).chr(0xa9); $cn_str .= " ".chr(0xe8).chr(0x91).chr(0x97); imageline($img, 0, 40, 200, 40, $line_color); imageline($img, 0, 260, 200, 260, $line_color); //豎排顯示“西遊記”3字 imagettftext($img, 30, 0, 10, 80, $line_color, $font_type,$cn_char1); imagettftext($img, 30, 0, 10, 120, $line_color, $font_type,$cn_char2); imagettftext($img, 30, 0, 10, 160, $line_color, $font_type,$cn_char3); //橫排顯示“吳承恩著”4字 imagettftext($img, 15, 0, 90, 254, $line_color, $font_type,$cn_str); imagepng($img); imagedestroy($img); //6 開啟已存在的圖片。 $img=imagecreatefromjpeg("tower.jpg"); imagejpeg($img); imagedestroy($img); //7 擷取圖片的相關屬性。 $img=imagecreatefromjpeg("tower.jpg"); $x = imagesx($img); $y = imagesy($img); echo "圖片tower.jpg的寬為:<b>$x</b> pixels"; echo "<br/>"; echo "<br/>"; echo "圖片tower.jpg的高為:<b>$y</b> pixels"; //8 函數getimagesize()的用法。 $img_info=getimagesize("tower.jpg"); for($i=0; $i<4; ++$i) { echo $img_info[$i]; echo "<br/>"; } |