如何使用 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); ?>
輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP