13.1.3 繪制各種圖形

13.1.3 繪制各種圖形

imagefill -- 區(qū)域填充
語(yǔ)法:bool imagefill(resource image,int x,int y, int color)
imagefill() 在 image 圖像的坐標(biāo) x,y(圖像左上角為 0, 0)處用 color 顏色執(zhí)行區(qū)域填充(即與 x, y 點(diǎn)顏色相同且相鄰的點(diǎn)都會(huì)被填充)。
imagesetpixel -- 畫一個(gè)單一像素
語(yǔ)法:bool imagesetpixel ( resource image, int x, int y, int color )
imagesetpixel() 在 image 圖像中用 color 顏色在 x,y 坐標(biāo)(圖像左上角為 0,0)上畫一個(gè)點(diǎn)。
imageline -- 畫一條線段
語(yǔ)法:bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imageline() 用 color 顏色在圖像 image 中從坐標(biāo) x1,y1 到 x2,y2(圖像左上角為 0, 0)畫一條線段。

imagerectangle -- 畫一個(gè)矩形
語(yǔ)法:bool imagerectangle ( resource image, int x1, int y1, int x2, int y2, int col )
imagerectangle() 用 col 顏色在 image 圖像中畫一個(gè)矩形,其左上角坐標(biāo)為 x1, y1,右下角坐標(biāo)為 x2, y2。圖像的左上角坐標(biāo)為 0, 0。
imagefilledrectangle -- 畫一矩形并填充
語(yǔ)法:bool imagefilledrectangle ( resource image, int x1, int y1, int x2, int y2, int color )
imagefilledrectangle() 在 image 圖像中畫一個(gè)用 color 顏色填充了的矩形,其左上角坐標(biāo)為 x1,y1,右下角坐標(biāo)為 x2,y2。0, 0 是圖像的最左上角。

imageellipse -- 畫一個(gè)橢圓
語(yǔ)法:bool imageellipse ( resource image, int cx, int cy, int w, int h, int color )
imageellipse() 在 image 所代表的圖像中畫一個(gè)中心為 cx,cy(圖像左上角為 0, 0)的橢圓。w 和 h 分別指定了橢圓的寬度和高度,橢圓的顏色由 color 指定。
imagefilledellipse -- 畫一橢圓并填充
語(yǔ)法:bool imagefilledellipse ( resource image, int cx, int cy, int w, int h, int color )
imagefilledellipse() 在 image 所代表的圖像中以 cx,cy(圖像左上角為 0, 0)為中心畫一個(gè)橢圓。w 和 h 分別指定了橢圓的寬和高。橢圓用 color 顏色填充。如果成功則返回 TRUE,失敗則返回 FALSE。

imagearc -- 畫橢圓弧
bool imagearc ( resource image, int cx, int cy, int w, int h, int s, int e, int color )
imagearc() 以 cx,cy(圖像左上角為 0, 0)為中心在 image 所代表的圖像中畫一個(gè)橢圓弧。w 和 h 分別指定了橢圓的寬度和高度,起始和結(jié)束點(diǎn)以 s 和 e 參數(shù)以角度指定。0°位于三點(diǎn)鐘位置,以順時(shí)針?lè)较蚶L畫。
imagefilledarc -- 畫一橢圓弧且填充
bool imagefilledarc ( resource image, int cx, int cy, int w, int h, int s, int e, int color, int style )
imagefilledarc() 在 image 所代表的圖像中以 cx,cy(圖像左上角為 0, 0)畫一橢圓弧。如果成功則返回 TRUE,失敗則返回 FALSE。w 和 h 分別指定了橢圓的寬和高,s 和 e 參數(shù)以角度指定了起始和結(jié)束點(diǎn)。style 可以是下列值按位或(OR)后的值:
IMG_ARC_PIE IMG_ARC_CHORD
IMG_ARC_NOFILL IMG_ARC_EDGED

imagestring -- 水平地畫一行字符串
語(yǔ)法:bool imagestring ( resource image, int font, int x, int y, string s, int col )
imagestring() 用 col 顏色將字符串 s 畫到 image 所代表的圖像的 x,y 坐標(biāo)處(這是字符串左上角坐標(biāo),整幅圖像的左上角為 0,0)。如果 font 是 1,2,3,4 或 5,則使用內(nèi)置字體。
imagestringup -- 垂直地畫一行字符串
語(yǔ)法:bool imagestringup ( resource image, int font, int x, int y, string s, int col )
imagestring()用 col 顏色將字符串 s 垂直地畫到 image 所代表的圖像的 x, y 座標(biāo)處(圖像的左上角為 0, 0)。如果 font 是 1,2,3,4 或 5,則使用內(nèi)置字體。

imagechar -- 水平地畫一個(gè)字符
語(yǔ)法:bool imagechar ( resource image, int font, int x, int y, string c, int color )
imagechar() 將字符串 c 的第一個(gè)字符畫在 image 指定的圖像中,其左上角位于 x,y(圖像左上角為 0, 0),顏色為 color。如果 font 是 1,2,3,4 或 5,則使用內(nèi)置的字體(更大的數(shù)字對(duì)應(yīng)于更大的字體)。
imagecharup -- 垂直地畫一個(gè)字符
語(yǔ)法:bool imagecharup ( resource image, int font, int x, int y, string c, int color )
imagecharup() 將字符 c 垂直地畫在 image 指定的圖像上,位于 x,y(圖像左上角為 0, 0),顏色為 color。如果 font 為 1,2,3,4 或 5,則使用內(nèi)置的字體。
imagettftext -- 用 TrueType 字體向圖像寫入文本
語(yǔ)法 :array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )

<?php
    $im = imagecreatetruecolor(400, 30);     //創(chuàng)建400x300像素大小的畫布
    $white = imagecolorallocate($im, 255, 255, 255);  //創(chuàng)建白色
    $grey = imagecolorallocate($im, 128, 128, 128);   //創(chuàng)建灰色
    $black = imagecolorallocate($im, 0, 0, 0);           //創(chuàng)建黑色
    imagefilledrectangle($im, 0, 0, 399, 29, $white);     //使用白色作為背景
     //如果有中文輸出,需要將其轉(zhuǎn)碼,轉(zhuǎn)換為UTF-8的字符串才可以直接傳遞
    $text=iconv("GB2312", "UTF-8", "LAMP兄弟連--無(wú)兄弟,不編程!");
    $font = ‘simsun.ttc’;   //指定字體,將系統(tǒng)中對(duì)應(yīng)字體復(fù)制到當(dāng)前目錄下
    imagettftext($im, 20, 0, 12, 21, $grey, $font, $text);   //輸出灰色字串作為陰影
    imagettftext($im, 20, 0, 10, 20, $black, $font, $text);  //輸出一個(gè)黑色的字符串
    header("Content-type: image/png");  //通知瀏覽器將輸出格式為PNG的圖像
    imagepng($im);  //向?yàn)g覽器中輸出PNG格式的圖像
    imagedestroy($im);      //銷毀資源,釋放內(nèi)存占用的空間

demo.html

<img src="test.php" />

test.php

<?php
    //1 創(chuàng)建資源(畫布的大?。?    $img = imagecreatetruecolor(200, 200);  
    //設(shè)置畫布的顏色
    $white =  imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
    $red =  imagecolorallocate($img, 255, 0, 0);
    $blue =  imagecolorallocate($img, 0, 0, 0XFF);
    $pink =  imagecolorallocate($img, 0XFF, 0, 0XFF);
    $green =  imagecolorallocate($img, 0, 0xFF, 0);
    
    
    imagefill($img, 0, 0, $white);
    //2. 制作各種顏色
    
    imageline($img, 0,0, 200,200, $blue);
    imageline($img, 200, 0, 0, 200, $red);


    //畫矩形
    imagerectangle($img, 50, 50, 150, 150, $pink);
    imagefilledrectangle($img, 75,75, 125,125, $blue);
    
    //畫圓
    imageellipse($img, 50, 50, 100, 100, $red);
    imagefilledellipse($img, 150, 150, 100, 100, $red);


    //畫弧形
    imagearc($img, 150, 50, 100, 100,  -90, 0, $blue);


    //畫一個(gè)字符串
    imagestring($img, 5, 50, 150, "hello world", $blue);
    imagestringup($img, 5, 50, 150, "hello world", $blue);

    //3. 畫出各種圖形,和寫(畫出)字
    imagettftext($img, 30, 0, 10, 100, $green, "./simkai.ttf", "妹子漂亮嗎?");
    imagettftext($img, 30, 0, 13, 103, $red, "./simkai.ttf", "妹子漂亮嗎?");

    //4保存,或輸出給瀏覽, 寫第二個(gè)參數(shù)就是保存
    header("Content-Type:images/gif");

    imagegif($img);

    //5. 釋放資源
    imagedestroy($img);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • PHP中GD庫(kù)的使用 GD簡(jiǎn)介 PHP 不僅限于只產(chǎn)生 HTML 的輸出,還可以創(chuàng)建及操作多種不同格式的圖像文件。...
    dptms閱讀 1,087評(píng)論 0 2
  • 本文講解常用GD函數(shù)的應(yīng)用 1.一個(gè)簡(jiǎn)單的圖像 我們先看一個(gè)例子: 運(yùn)行結(jié)果: 這段代碼中我們用了一下幾個(gè)函數(shù): ...
    老馬的春天閱讀 1,608評(píng)論 2 8
  • 背景 驗(yàn)證碼就是把一串隨機(jī)產(chǎn)品的數(shù)字動(dòng)態(tài)生成一幅圖片,再加上干擾元素。此時(shí)用戶可以通過(guò)肉眼能識(shí)別里面的數(shù)字或者字符...
    dy2903閱讀 2,348評(píng)論 0 7
  • pygame圖形接口 使用pygame.image模塊,可以對(duì)圖像進(jìn)行讀取和保存。 使用pygame.image....
    sssally92閱讀 17,859評(píng)論 1 25
  • 舊福印上壓了新福, 黏著油垢的鍋被刷洗了干凈, 鍋里的雞和上次的雞, 一個(gè)走了一生另一個(gè)走了十二年, 一個(gè)去遠(yuǎn)足另...
    葡萄美酒閱讀 287評(píng)論 0 0

友情鏈接更多精彩內(nèi)容