php 建立映像執行個體_PHP教程

來源:互聯網
上載者:User
使用ImageCreate()建立一個代表空白映像的變數,這個函數要求以像素為單位的映像大小的參數,其格式是ImageCreate(x_size, y_size)。如果要建立一個大小為250×250的映像,就可以使用下面的語句:   

<? header ("content-type: image/png");  

  使用imagecreate()建立一個代表空白映像的變數,這個函數要求以像素為單位的映像大小的參數,其格式是imagecreate(x_size, y_size)。如果要建立一個大小為250×250的映像,就可以使用下面的語句:   

  $newimg = imagecreate(250,250);  

 

  由於映像還是空白的,因此你可能會希望用一些彩色來填充它。你需要首先使用imagecolorallocate()函數用其rgb值為這種顏色指定一個名字,這一函數的格式為imagecolorallocate([image], [red], [green], [blue])。如果要定義天藍色,可以使用如下的語句:  

  $skyblue = imagecolorallocate($newimg,136,193,255);  

 

  接下來,需要使用imagefill()函數用這種顏色填充這個映像,imagefill()函數有幾個版本,例如imagefillrectangle()、imagefillpolygon()等。為簡單起見,我們通過如下的格式使用imagefill()函數:  

  imagefill([image], [start x point], [start y point], [color])

  imagefill($newimg,0,0,$skyblue);  

 

  最後,在映像建立後釋放映像控制代碼和所佔用的記憶體:  

 

 imagepng($newimg);

  imagedestroy($newimg); ?>

  這樣,建立映像的全部代碼如下所示:

php教程代碼:
 

<? header ("content-type: image/png");

  $newimg = imagecreate(250,250);

  $skyblue = imagecolorallocate($newimg,136,193,255);

  imagefill($newimg,0,0,$skyblue);

  imagepng($newimg);

  imagedestroy($newimg);

  ?>   

http://www.bkjia.com/PHPjc/633012.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633012.htmlTechArticle使用ImageCreate()建立一個代表空白映像的變數,這個函數要求以像素為單位的映像大小的參數,其格式是ImageCreate(x_size, y_size)。如果要建立一...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.