(PHP 5, PHP 7, PHP 8)
imagexbm — 將 XBM 影像輸出到瀏覽器或檔案
輸出或儲存給定 image
的 XBM 版本。
注意: imagexbm() 不會套用任何填補,因此影像寬度必須為 8 的倍數。此限制自 PHP 7.0.9 起不再適用。
image
一個 GdImage 物件,由其中一個影像建立函式返回,例如 imagecreatetruecolor()。
filename
儲存檔案的路徑,以 string 類型給定。如果是 null
,則會直接輸出原始影像串流。
filename
(不含 .xbm 副檔名)也會用於 XBM 的 C 語言識別字,其中目前語系中的非字母數字字元會被底線取代。如果 filename
設為 null
,則會使用 image
來建構 C 語言識別字。
foreground_color
您可以透過此參數設定前景顏色,方法是設定從 imagecolorallocate() 獲得的識別碼。預設的前景顏色是黑色。所有其他顏色都被視為背景。
版本 | 說明 |
---|---|
8.0.0 |
image 現在需要一個 GdImage 實例;先前需要一個有效的 gd 資源。 |
8.0.0 |
foreground_color 現在可以為 null。 |
8.0.0 | 已移除未使用的第四個參數。 |
範例 #1 儲存 XBM 檔案
<?php
// 建立一張空白圖片並加入文字
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, '一段簡單的文字', $text_color);
// 儲存圖片
imagexbm($im, 'simpletext.xbm');
// 釋放記憶體
imagedestroy($im);
?>
範例 #2 使用不同的前景顏色儲存 XBM 檔案
<?php
// 建立一張空白圖片並加入文字
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, '一段簡單的文字', $text_color);
// 設定替代前景顏色
$foreground_color = imagecolorallocate($im, 255, 0, 0);
// 儲存圖片
imagexbm($im, NULL, $foreground_color);
// 釋放記憶體
imagedestroy($im);
?>