當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imagexbm()用法及代碼示例

imagexbm()函數是PHP中的內置函數,用於顯示圖像以瀏覽文件。此函數的主要用途是在瀏覽器中查看圖像並將任何其他圖像類型轉換為XBM。

用法:

bool imagexbm( resource $image, int $to, int $foreground)

參數:此函數接受上述和以下所述的三個參數:


  • $image:它指定要處理的圖像資源。
  • $to (Optional):它指定將文件保存到的路徑。
  • $foreground (Optional):它指定圖像的前景。

返回值:如果成功,此函數將返回TRUE,否則將返回FALSE。

以下示例說明了PHP中的imagexbm()函數:

範例1:在此示例中,我們將在瀏覽器中下載圖像。

<?php 
  
// Load an xbm image from local folder 
// Image can be converted into xbm using 
// online convertors or imagexbm() 
$im = imagecreatefromxbm('geeksforgeeks.xbm'); 
  
// Download the image 
header('Content-Type:image/xbm'); 
imagexbm($im); 
imagedestroy($im); 
?>

輸出:

This will download your image as download, 
further you can rename this file to anything like 
geeksforgeeks.xbm and use it.

範例2:在此示例中,我們將PNG轉換為XBM。

<?php 
  
// Load an image from PNG URL 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Convert the image into XBM using imagexbm() function 
imagexbm($im, 'converted.xbm'); 
imagedestroy($im); 
?>

輸出:

This will save the XBM version of image in the same 
folder where your PHP script is.

參考: https://www.php.net/manual/en/function.imagexbm.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagexbm() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。