如何在php 7

时间:2017-08-29 10:05:46

标签: php gd

我使用php 7.0.22(Ubuntu 17.04)

当某些用户使用截断数据上传PNG时,我使用:

$a = imagecreatefrompng($path);

然后我崩溃了:

Fatal error: imagecreatefrompng(): gd-png: fatal libpng error: Read Error: truncated data in ###.php on line ###

我尝试使用

try{...code...}catch(\Throwable $e){...echo...}.

$a = @imagecreatefrompng($path);

但是脚本会因为相同的错误消息而死掉。 使用imagecreatefromstring(file_get_contents($path))会产生相同的结果。

我对PNG的验证:我使用函数getimagesize($filename)返回Array ( [0] => 1045 [1] => 734 [2] => 3 [3] => width="1045" height="734" [bits] => 8 [mime] => image/png )

如何使用截断数据PNG文件处理函数imagecreatefrompng()imagecreatefromstring()

UPD:这是Ubuntu上的PHP7错误https://bugs.php.net/bug.php?id=73986 糟糕的工作方式:

$output = `php -r "imagecreatefrompng('$fname');" 2>&1`;
if (!empty($output)){
    return false; // handle error
} else {
    $result = imagecreatefrompng($fname);
}

0 个答案:

没有答案