使用 PHP 創(chuàng)建 PNG 圖像

示例 #1 使用 PHP 創(chuàng)建 PNG 圖像

<?php

header
("Content-type: image/png");
$string $_GET['text'];
$im     imagecreatefrompng("images/button1.png");
$orange imagecolorallocate($im22021060);
$px     = (imagesx($im) - 7.5 strlen($string)) / 2;
imagestring($im3$px9$string$orange);
imagepng($im);
imagedestroy($im);

?>
本例程需要從帶有 <img src="button.php?text=text"> 標簽的頁面調(diào)用。 上述 button.php 腳本將 "text" 字符串繪制到一個圖像上, 在本例中圖像文件為 "images/button1.png", 然后輸出繪制后的圖像。 當(dāng)你需要經(jīng)常修改圖像上的文字時, 動態(tài)生成圖像就可以省去了每次都重新制作圖像的麻煩。