如何使用 PHP 中的 imagecreatefromwebp() 函式,從 WEBP 檔案或 URL 建立新影像?


在 PHP 中,imagecreatefromwebp() 是一個內建函式,用於從 WEBP 檔案或 URL 中建立新影像。imagecreatefromwebp() 返回一個影像識別符號,它表示從給定的 filename 中獲取的影像。

只要我們希望在從 WEBP 檔案載入影像後對其進行編輯時,都可以使用 imagecreatefromwebp()
使用 imagewebp() 可以將影像轉換為 WBMP。

語法

resource imagecreatefromwebp(string $filename)

引數

imagecreatefromwebp() 只需一個引數,$filename,它儲存影像的名稱。

返回值

如果成功,imagecreatefromwebp() 將返回一個影像資源識別符號,如果失敗,它將產生一個錯誤。

示例 1

<?php
   // Loading the WEBP image from the local drive folder
   $img = imagecreatefromwebp('C:\xampp\htdocs\Images\img31.webp');
   
   // View the loaded image in the browser
   imagewbmp($img);
   imagedestroy($img);
?>

輸出

Note − The above PHP code will load the content into the browser in an
unsupported form of text because the browser does not support the WEBP image format.

示例 2

<?php
   // Load a WEBP image from the local drive folder
   //We can convert the image to WEBP using the online converter
   //or using the imagewebp() function
   $img = imagecreatefromwebp('C:\xampp\htdocs\Images\img31.webp');

   // Save the GIF image into the given local drive folder path.
   imagejpeg($img,'C:\xampp\htdocs\pic.gif');
   imagedestroy($img);
?>

輸出

更新日期: 2021 年 8 月 9 日

1000+ 次觀看

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.