imagewebp
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
imagewebp — 將 WebP 格式的影象輸出到瀏覽器或檔案
說明
   將 image 參數指定的影象以 WebP 格式輸出到瀏覽器或者儲存到檔案。
  
參數
- 
image
- 
由圖像建立函式(例如imagecreatetruecolor())返回的 GdImage 對象。 
- 
to
- 
      檔案儲存的路徑或者已打開的流資源(此方法返回后自動關閉該流資源),如果未設定或為 null,將會直接輸出原始圖像流。
- 
quality
- 
      quality範圍從0(最低質量,最小檔案體積)到100 (最好質量, 最大檔案體積)。
返回值
   成功時返回 true, 或者在失敗時返回 false。
  
更新日誌
| 版本 | 說明 | 
|---|---|
| 5.4.0 | 支援把 resource 流作為 to參數傳入。 | 
範例
示例 #1 儲存為 WebP 影象檔案
<?php
// 建立一個空影象並在其上加入一些文字
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'WebP with PHP', $text_color);
// 儲存影象
imagewebp($im, 'php.webp');
// 釋放記憶體
imagedestroy($im);
?>