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


PHP imagewbmp()用法及代碼示例

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

用法:

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

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


  • $image:它指定要執行操作的圖像資源文件。
  • $to (Optional):它指定保存文件的路徑。
  • $foreground (Optional):它指定圖像的前景。

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

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

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

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

輸出:

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

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

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

輸出:

This will save the WBMP version of image in the same
folder where your PHP script exist.

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



相關用法


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