PHP映像圖形處理入門教程這款php圖片產生教程是一款從產生一個簡單的映像到產生複雜的圖形的php教程,人簡單就複雜有12個產生映像執行個體。1 產生一個簡單映像。
php教程映像圖形處理入門教程
這款php圖片產生教程是一款從產生一個簡單的映像到產生複雜的圖形的php教程,人簡單就複雜有12個產生映像執行個體。
1 產生一個簡單映像。
2 設定映像的顏色。
3 在映像上繪製直線。
4 在映像上顯示文字。
5 在映像中顯示中文字元。
6 開啟已存在的圖片。
7 擷取圖片的相關屬性。
8 函數getimagesize()的用法。
9 為上傳圖片添加浮水印效果。
10 產生已有圖片的縮圖。
11 使用函數imagecopyresampled()。
12 產生帶有底紋的數字驗證碼圖片的php程式。
*/
//1 產生一個簡單映像。
$width = 200;
$height =200;
$img = imagecreatetruecolor($width,$height) or die("不支援gd影像處理");
imagepng($img);
imagedestroy($img);
//2 設定映像的顏色。
$width = 200;
$height =200;
$img = imagecreatetruecolor($width,$height) or die("不支援gd影像處理");
$bg_color = imagecolorallocate($img, 255, 0, 0);
imagefill($img, 0, 0, $bg_color);
imagepng($img);
imagedestroy($img);
//3 在映像上繪製直線。
$width = 200;
$height =300;
$img = imagecreatetruecolor($width,$height) or die("不支援gd影像處理");
$line_color = imagecolorallocate($img, 255, 255, 255);
imageline($img,0,40,200,40,$line_color);
imageline($img,0,260,200,260,$line_color);
imagepng($img);
imagedestroy($img);
//4 在映像上顯示文字。
$width = 200;
$height =300;
$img = imagecreatetruecolor($width,$height) or die("不支援gd影像處理");
$line_color = imagecolorallocate($img, 255, 255, 255);
imageline($img, 0, 40, 200, 40, $line_color);
imageline($img, 0, 260, 200, 260, $line_color);
imagestring($img, 5, 0, 60, "it's time to learn php!", $line_color);
imagepng($img);
imagedestroy($img);
//5 在映像中顯示中文字元。
$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的寬為:$x pixels";
echo "
";
echo "
";
echo "圖片tower.jpg的高為:$y pixels";
//8 函數getimagesize()的用法。
$img_info=getimagesize("tower.jpg");
for($i=0; $i<4; ++$i)
{
echo $img_info[$i];
echo "
";
}
?>
1 2 3
http://www.bkjia.com/PHPjc/633033.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633033.htmlTechArticlePHP映像圖形處理入門教程這款php圖片產生教程是一款從產生一個簡單的映像到產生複雜的圖形的php教程,人簡單就複雜有12個產生映像執行個體。...