php圖形處理教程-php產生圖片(1/4)

來源:互聯網
上載者:User

在web應用中經常會用到產生圖片這一功能,在php教程 中建立圖片需要gd庫的支援才能建立圖形,有了這個圖形功能,我們就可以方便的產生縮圖,驗證碼,給圖片加浮水印等。

在php中要安裝gd庫才能正常運行建立圖片功能,方法如下,在win系統,找到php.ini把

;extension=php_gd2.dll前面的";"去了,重起apache就OK了。

下面我們一看執行個體

php的gd庫可以產生多種影像檔,如gif,png,jpg,wbmp,xpm等,下面來看一個產生正方形的檔案。

<?php
$height = 300;
$width = 300;
//建立背景圖
$im = ImageCreateTrueColor($width, $height);
//分配顏色
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
//繪製顏色至映像中
ImageFill($im, 0, 0, $blue);
//繪製字串:Hello,PHP
ImageString($im, 10, 100, 120, 'Hello,PHP', $white);
//輸出映像,定義頭
Header ('Content-type: image/png');
//將映像發送至瀏覽器
ImagePng($im);
//清除資源
ImageDestroy($im);
?>

查看結果只要瀏覽php檔案就可以了,如果要映像調用<img src=a.php />

執行個體二,使用基本函數建立圖片imagecreate()

resource imagescreate(int x,inty)

imagedestroy 是放圖片所佔記憶體空間

int ingaedestroy( image)

imagecopy()

int imagecopy( dst_im,sr_im,int x,int y,int x,int y,)

首頁 1 2 3 4 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.