PHP圖片處理---畫各種圖像


/*
*
* PHP 圖像處理
*
* 一:畫圖
*
* 驗證碼、統計圖(餅狀圖。條形圖等)
*
*   二:處理原有的圖像
*
* 縮放、加水印、電子相冊
*
*       GIF PNG JPG WBMP XBM
*
* FreeType Type1 宋體 黑體 楷體
*/


/*
*    安裝GD庫----lamp環境安裝
*
* 1、創建畫布---資源類型---高度 寬度
* 2、繪製圖像---制定各種顏色---矩形 園 點 線段 扇形  畫字符(字符串,freetype字體)
* 3、輸出圖像||保存處理好的圖像
* 4、釋放資源
*/


//step1 創建圖片資源
$imgsource=imagecreatetruecolor(200, 200);
//step2 畫各種圖形
       //創建顏色
$red=imagecolorallocate($imgsource,255,0,0);
$yellow=imagecolorallocate($imgsource,255, 255, 0);
$green=imagecolorallocate($imgsource,0, 255, 0);
$blue=imagecolorallocate($imgsource,0, 0, 255);
$white=imagecolorallocate($imgsource, 255, 255, 255);
$gray=imagecolorallocate($imgsource, 0xC0, 0xC0, 0xC0);
$darkgray=imagecolorallocate($imgsource, 0x90, 0x90, 0x90);
$nacy=imagecolorallocate($imgsource, 0, 0, 0x80);
$darknacy=imagecolorallocate($imgsource, 0, 0, 0x50);
$darkred=imagecolorallocate($imgsource,0x90, 0, 0);
            //填充顏色
imagefill($imgsource, 0, 0, $red);
//畫各種圖像
//畫矩形
imagefilledrectangle($imgsource, 5, 5, 80, 80, $yellow);  //畫一個矩形並填充
imagerectangle($imgsource, 80, 80, 180, 180, $green);     //畫一個矩形不填充
//畫線段
imageline($imgsource, 0, 0, 200, 200, $blue);
//畫點
imagesetpixel($imgsource, 185, 85, $yellow);
//畫橢圓(園)
imagefilledellipse($imgsource, 50, 100, 50, 50, $blue);      //畫一個橢圓(圓)並填充
imageellipse($imgsource, 100, 50, 50, 50, $blue);            //畫一個橢圓(圓)並填充


 
  //畫字
  imagechar($imgsource, 5, 50, 50, "A", $darkgray);            //水平畫
  imagecharup($imgsource, 5, 80, 80, "B", $darkgray);           //垂直畫
  //畫字符串
  imagestring($imgsource, 5, 90, 90, "HELLOW", $darkgray);      //垂直畫
  imagestringup($imgsource, 5, 120, 120, "HELLOW", $darkgray);   //水平畫
  //畫支持freetype字體的
  //array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )
  //可以使用 iconv 進行調整
  imagettftext($imgsource,24,60,150,150,$darknavy,"ygyxsziti2.0.ttf","程歡歡");
//step3 輸出或保存圖像
header("Content-type:image/gif");
imagegif($imgsource);
//imagejpeg($imgsource);
//imagepng($imgsource);
//step4 釋放資源

imagedestroy($imgsource);


        

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章