php imagecreatefromstring()不工作

php imagecreatefromstring()不工作,php,image,Php,Image,我有一个脚本,可以将用户上传的图像保存到MySQL数据库,然后在另一个位置访问它们。还有一个选项,他们可以在其中裁剪图像,这将正确地工作到。但是,当我尝试渲染裁剪的图像(正常图像工作正常)时,我会得到以下结果: Warning: imagecreatefromstring(): gd-png: fatal libpng error: Read Error: truncated data in /home/retweety/public_html/uploadr/get.php on line 9

我有一个脚本,可以将用户上传的图像保存到MySQL数据库,然后在另一个位置访问它们。还有一个选项,他们可以在其中裁剪图像,这将正确地工作到。但是,当我尝试渲染裁剪的图像(正常图像工作正常)时,我会得到以下结果:

Warning: imagecreatefromstring(): gd-png: fatal libpng error: Read Error: truncated data in /home/retweety/public_html/uploadr/get.php on line 92
Warning: imagecreatefromstring(): gd-png error: setjmp returns error condition in /home/retweety/public_html/uploadr/get.php on line 92
Warning: imagecreatefromstring(): Passed data is not in 'PNG' format in /home/retweety/public_html/uploadr/get.php on line 92
Warning: imagecreatefromstring(): Couldn't create GD Image Stream out of Data in /home/retweety/public_html/uploadr/get.php on line 92
Warning: imagecrop() expects parameter 1 to be resource, boolean given in /home/retweety/public_html/uploadr/get.php on line 93
Warning: imagepng() expects parameter 1 to be resource, null given in /home/retweety/public_html/uploadr/get.php on line 96
Warning: imagedestroy() expects parameter 1 to be resource, null given in /home/retweety/public_html/uploadr/get.php on line 97
这是我的代码:

$imgdata = $row['original']; // Line 86
$variables = json_decode($row['cropped']); // Line 87

$im = imagecreatefromstring($imgdata); // Line 89
$im2 = imagecrop($im, ['x' => $variables->x, 'y' => $variables->y, 'width' => $variables->width, 'height' => $variables->height]); // Line 90
if ($im2 !== FALSE) { // Line 91
    header('Content-Type: image/png'); // Line 92
    imagepng($im2); // Line 93
    imagedestroy($im2); // Line 94
} else { // Line 95
    echo "Could not crop image."; // Line 96
} // Line 97
编辑: 这是其中一张图片的$variables的var_转储

object(stdClass)#3 (4) { ["x"]=> int(87) ["y"]=> int(15) ["width"]=> int(142) ["height"]=> int(82) }
$imgdata包含原始图像数据。我在下面的URL上有相同图像的base64编码版本的数据。我没有把它贴在这里,因为它太长了


我用
$imgdata
测试了您的代码。 对我来说,数据库中存储的图像源似乎已损坏。 否则,您将能够无误地显示原始图像。我无法通过此代码显示图像。我也犯了同样的错误

$imgdata = base64_decode($imgdata);
$im      = imagecreatefromstring($imgdata);
if ($im !== false) {
  header('Content-Type: image/png');
  imagepng($im);
  imagedestroy($im);
}

您能否显示echo var_dump($variables)的输出?能否为
$row['original']
添加一个示例值?