這篇文章將為大家詳細講解有關(guān)php怎么創(chuàng)建圖像,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)廊坊,十多年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
php創(chuàng)建圖像具體步驟:1、設(shè)定標頭,告訴瀏覽器要生成的MIME類型;2、創(chuàng)建一個畫布;3、進行顏色管理;4、填充顏色;5、繪制圖形和文字;6、輸出圖像;7、銷毀圖像。
本文操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
PHP 創(chuàng)建圖像的具體步驟
共三種類型:
header(‘content-type:image/png’)
header ( ‘content-type: image/gif’);
header ( ‘content-type: image/jpeg’ );
<?php header("content-type: image/png");
resource imagecreatetruecolor ( int $width , int $height )新建一個真彩色圖像
返回一個圖像標識符,代表了一幅大小為 width 和 height 的黑色圖像。
返回值:成功后返回圖象資源,失敗后返回 FALSE 。
$width = 200; $height = 100; $img = imagecreatetruecolor($width,$height);
**int imagecolorallocate ( resource $image , int $red , int $green , int $blue )**為一幅圖像分配顏色
red , green 和 blue 分別是所需要的顏色的紅,綠,藍成分。這些參數(shù)是 0 到 255 的整數(shù)或者十六進制的 0x00 到 0xFF
$color = imagecolorallocate($img,0xcc,0xcc,0xcc); // 灰色
bool imagefill ( resource $image , int $x , int $y , int $color )
image 圖像的坐標 x , y (圖像左上角為 0, 0)處用 color 顏色執(zhí)行區(qū)域填充(即與 x, y 點顏色相同且相鄰的點都會被填充)。
imagefill($img,0,0,$color);
imagesetpixel()在 image 圖像中用 color 顏色在 x , y 坐標(圖像左上角為 0,0)上畫一個點。
bool imagesetpixel ( resource $image , int $x , int $y , int $color )
例:在畫布上隨機畫100個點
for ($i= 0; $i < 100; $i++) { $color = imagecolorallocate($img,rand(0,25), rand(0,255), rand(0,255)); $x = rand(0,$width); $y = rand(0,$height); imagesetpixel($img, $x, $y, $color); }
imageline()用 color 顏色在圖像 image 中從坐標 x1 , y1 到 x2 , y2 (圖像左上角為0, 0)畫一條線段。
bool imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
例:在畫布上隨機畫10條線段
for ($i= 0; $i < 10; $i++) { $color = imagecolorallocate($img,rand(0,25), rand(0,255), rand(0,255)); $x = rand(0,$width); $y = rand(0,$height); $x1 = rand(0,$width); $y1 = rand(0,$height); imageline($img, $x, $y, $x1, $y1,$color); }
imagerectangle()用 col 顏色在 image 圖像中畫一個矩形,其左上角坐標為 x1, y1,右下角坐標為x2, y2。圖像的左上角坐標為 0, 0。
bool imagerectangle ( resource $image , intbool imagerectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $col )
imagefilledrectangle()在 image 圖像中畫一個用 color 顏色填充了的矩形,其左上角坐標為 x1,y1 ,右下角坐標為 x2 , y2 。0, 0 是圖像的最左上角。
bool imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
繪制文字
array imagettftext ( resource $image , float $size , float $anglearray imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text)
size :字體的尺寸。根據(jù) GD 的版本,為像素尺寸(GD1)或點(磅)尺寸(GD2)。
angle :角度制表示的角度,0 度為從左向右讀的文本。更高數(shù)值表示逆時針旋轉(zhuǎn)。例如 90 度表示從下向上讀的文本。
由 x , y 所表示的坐標定義了第一個字符的基本點(大概是字符的左下角)。
color :顏色索引
fontfile :是想要使用的 TrueType 字體的路徑。 (從我的電腦c盤里的Windows的fonts文件夾里找)
text :UTF-8 編碼的文本字符串。
$color = imagecolorallocate($img,154, 75, 65)); $font = "simsunb.ttf"; $str = "hello , how are you?"; imagettftext($img, 30, 45, $x, $y, $color, $font, $str);
三種方式:
bool imagepng ( resource $image [, string $filename ] )
將 GD 圖像流(image )以 PNG 格式輸出到標準輸出(通常為瀏覽器),或者如果用 filename 給出了文件名則將其輸出到該文件。
bool imagegif ( resource $image [, string $filename ] )
bool imagejpeg ( resource $image [, string $filename [, int
$quality ]])
imagepng($img);
bool imagedestroy ( resource $image )
釋放與 image 關(guān)聯(lián)的內(nèi)存
imagedestroy($img);
關(guān)于“php怎么創(chuàng)建圖像”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
分享文章:php怎么創(chuàng)建圖像
文章源于:http://jinyejixie.com/article46/ppechg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、云服務(wù)器、定制網(wǎng)站、外貿(mào)建站、網(wǎng)站策劃、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)