Imagecreatefromwebp():WebP解码:无法解码输入数据

问题描述 投票:3回答:1

我正在尝试使用imagecreatefromwebp()将webp文件转换为JPEG但不幸的是,它会向我发出警告:警告:imagecreatefromwebp():WebP解码:无法解码输入数据。

这是我的代码

$filename = dirname(__FILE__)."\\".$keyword."1.webp"; // $keyword = 'xyz';

$im = imagecreatefromwebp($filename);

// Convert it to a jpeg file with 100% quality
imagejpeg($im, './example.jpeg', 100);
imagedestroy($im);

请帮忙。

php image jpeg image-conversion webp
1个回答
-1
投票

我正在使用此代码,它对我来说很好。这里$data包含base64encoded数据

$im = imagecreatefromwebp($data);
$imageResult = imagejpeg($im, $destinationPath . $fileName, 100);
imagedestroy($im);

imagecreatefromwebp()函数接受有效的fileURL。您还可以在该函数中传递二进制数据。您可以在这里查看函数定义和示例http://php.net/manual/en/function.imagecreatefromwebp.php

© www.soinside.com 2019 - 2024. All rights reserved.