(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)
imagegd — 將 GD 影像輸出到瀏覽器或檔案
影像
一個 GdImage 物件,由其中一個影像建立函式返回,例如 imagecreatetruecolor()。
檔案
要儲存檔案的路徑或開啟的串流資源(此函式返回後會自動關閉)。如果未設定或為 null
,則會直接輸出原始影像串流。
版本 | 說明 |
---|---|
8.0.3 |
file 現在可以為 null。 |
8.0.0 |
image 現在需要一個 GdImage 實例;以前需要一個有效的 gd 資源。 |
7.2.0 | imagegd() 現在允許輸出真彩色影像。以前,這些影像會被隱式轉換為調色盤。 |
範例 #1 輸出 GD 影像
<?php
// 建立空白影像並新增一些文字
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "一個簡單的文字字串", $text_color);
// 輸出影像
imagegd($im);
// 釋放記憶體
imagedestroy($im);
?>
範例 #2 儲存 GD 影像
<?php
// 建立一張空白圖片並添加一些文字
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
// 儲存 GD 圖片
// GD 圖片的檔案格式為 .gd,詳見 http://www.libgd.org/GdFileFormats
imagegd($im, 'simple.gd');
// 釋放記憶體
imagedestroy($im);
?>
備註:
GD 格式通常用於允許快速載入圖片的部分內容。請注意,GD 格式僅可用於與 GD 相容的應用程式。
GD 和 GD2 圖片格式是 libgd 的專有圖片格式。它們已被視為*過時*,並且僅應用於開發和測試目的。