內容說明:本函數用來建立一張 gif 格式圖形,參數 im 為使用 imagecreate() 所建立的圖片代碼,參數 filename 可省略,若無本參數 filename,則會將圖片指接送到瀏覽器端,記得在送出圖片之前要先送出使用 content-type: image/gif 的標頭字符串 (header) 到瀏覽器端,以順利傳輸圖片。若要使用透明背景的 gif 圖,也就是 gif89a 的格式,需要先使用 imagecolortransparent() 配置透明背景.
- $values=array(
- 40,50, //第一個頂點的坐標
- 20,240, //第一個頂點的坐標
- 60,60, //第一個頂點的坐標
- 240,20, //第一個頂點的坐標
- 50,40, //第一個頂點的坐標
- 10,10 //第一個頂點的坐標
- );
- $im=imagecreatetruecolor(250,250); //創建圖像
- $bg=imagecolorallocate($im,200,200,200); //定義灰色背景
- $yellow=imagecolorallocate($im,255,255,0); //定義黃色前景
- imagefilledpolygon($im,$values,6,$yellow); //畫出多邊形
- header('content-type: image/png');
- //判斷gif函數是否存在
- if(function_exists("imagegif"))
- {
- //如果存在,以gif格式輸出
- header("content-type: image/gif");
- imagegif($im);
- }
- //判斷jpeg函數是否存在
- elseif(function_exists("imagejpeg"))
- {
- //如果存在,以jpg格式輸出
- header("content-type: image/jpeg");
- imagejpeg($im, "", 0.5);
- }
- //判斷png函數是否存在
- elseif (function_exists("imagepng"))
- {
- //如果存在,以png格式輸出
- header("content-type: image/png");
- imagepng($im);
- }
- //判斷wbmp函數是否存在
- elseif (function_exists("imagewbmp"))
- {//開源代碼Vevb.com
- //如果存在,以bmp格式輸出
- header("content-type: image/vnd.wap.wbmp");
- /*
header() 函數向客戶端發送原始的 http 報頭,認識到一點很重要,即必須在任何實際的輸出被發送之前調用 header() 函數(在 php 4 以及更高的版本中,您可以使用輸出緩存來解決此問題):
- */
- imagewbmp($im);
- }
- else
- {
- //如果都不支持,輸出內容
- die("no image support in this php server");
- }
- /*
該代碼執行結果與代碼22-25類似,所不同的是,該代碼判斷多種圖像支持,然后用相應的格式輸出圖像.
語法:int imagegif(int im, string [filename]);
返回值:整數,函數種類:圖形處理
新聞熱點
疑難解答