imagewebp函数失败,没有生成任何错误

时间:2019-07-12 09:23:27

标签: php gd

我想将一个jpeg图像文件夹转换为另一个文件夹中的webp格式。我正在GD库中使用imagewebp函数。调用函数时,代码只是停止。尽管实际上创建了文件,但是文件的长度为零。没有错误。

  

gd_info显示具有WebP支持的2.1版。

     

php版本5.6

如果我更改为imagepng(),则一切正常,因此该库已安装并正常工作。

我尝试过处理单个小图像,以防出现内存问题,但仍然存在相同的问题。

还尝试了imagecreatefromjpeg而不是imagecreatefromstring,但是相同。

将质量过滤器删除为默认设置(例如,省略了65),但效果相同。

我还尝试将单个文件直接输出到浏览器。这适用于imagepng,但是imagewebp出现404错误

$jpgfiles = glob ('jpegs/*.jpg');
echo "<p>" . sizeof( $jpgfiles ) . " files found. </p>"; // Shows 7 files   
foreach($jpgfiles as $j) {
    echo "<p>Found $j</p>"; // Shows first found file
    $filename = substr( $j, 6, -4) . '.webp'; // Keep the same filename but change extension
    echo "<p>$filename</p>";
    $jpgimage = imagecreatefromstring( file_get_contents( $j ) );
    if( !$jpgimage ) die ("Failed on imagecreatefromstring");

   if( $webpimage = imagewebp( $jpgimage, 'webps/' . $filename, 65 )) echo "$filename created"; // This is never echo'd
   else die ("Failed on imagewebp"); // Doesn't die either
   imagedestroy ( $jpgimage );

}

我希望创建图像,但是程序执行停止。错误日志不包含任何信息。 die命令永远不会被调用。该webp文件已创建,但长度为零。

0 个答案:

没有答案