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