将PHP中的WebP格式转换为JPG格式可以使用GD库中的imagecreatefromwebp()和imagejpeg()函数。
-
使用imagecreatefromwebp()函数将WebP格式的图片读入到PHP中,如:$img = imagecreatefromwebp("image.webp");
-
创建一个新的JPG格式的画布,如:$new_img = imagecreatetruecolor($width, $height);
-
将WebP格式的图片复制到新的画布上,如:imagecopy($new_img, $img, 0, 0, 0, 0, $width, $height);
-
使用imagejpeg()函数将新的画布保存为JPG格式的图片,如:imagejpeg($new_img, "image.jpg", 100); 其中100表示JPG图片的质量,范围是0-100。
-
使用imagecreatefromwebp()函数将WebP格式的图片读入到PHP中,如:$img = imagecreatefromwebp("image.webp");
-
创建一个新的JPG格式的画布,如:$new_img = imagecreatetruecolor($width, $height);
-
将WebP格式的图片复制到新的画布上,如:imagecopy($new_img, $img, 0, 0, 0, 0, $width, $height);
-
使用imagejpeg()函数将新的画布保存为JPG格式的图片,如:imagejpeg($new_img, "image.jpg", 100); 其中100表示JPG图片的质量,范围是0-100。