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


PHP imagecreatefromwebp()用法及代碼示例

imagecreatefromwebp()函數是PHP中的內置函數,用於從WEBP文件或URL創建新圖像。 WEBP是一種采用有損和無損壓縮的圖像格式。該圖像可以在程序中進一步處理。從WEBP文件加載圖像後要編輯圖像時,通常使用此函數。可以使用imagewebp()函數將圖像轉換為WEBP。

用法:

resource imagecreatefromwebp( string $filename )

參數:該函數接受單個參數$filename,該參數保存圖像的名稱。


返回值:成功時此函數返回圖像資源標識符,錯誤時返回FALSE。

下麵給出的程序說明了PHP中的imagecreatefromwebp()函數:

程序1:

<?php 
// Load an WEBP image from local folder 
// You can convert any image to WEBP using 
// imagewebp() function or online convertors 
$im = imagecreatefromwebp('./geeksforgeeks.webp'); 
  
// View the loaded image in browser 
imagewebp($im); 
imagedestroy($im); 
?>

輸出:

This will load the content into browser in the form of unsupported text as browsers don’t support WEBP.

程序2:

<?php 
// Load an WEBP image from local folder 
// You can convert any image to WEBP using 
// imagewebp() function or online convertors 
$im = imagecreatefromwebp('./geeksforgeeks.webp'); 
  
// Output the image by converting it into PNG 
header('Content-type:image/png'); 
imagepng($im); 
imagedestroy($im); 
?>

輸出:

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



相關用法


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