我有一个名为 $png_file 的文件,它是从数据库中获取的字符串。我希望能够通过以下方式使用它:
$image = imagecreatefromstring($png_file);
$width = imagesx($image);
$height = imagesy($image);
这样我就可以获得作为字符串保存在数据库中的 png 文件的高度和宽度。
但是,每次我尝试这样做时,都会出现以下错误:
Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd-png: fatal libpng error: Read Error: truncated data in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: gd-png error: setjmp returns error condition in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Passed data is not in 'PNG' format in on line 39
Warning: imagecreatefromstring() [function.imagecreatefromstring]: Couldn't create GD Image Stream out of Data in on line 39
Warning: imagesx() expects parameter 1 to be resource, boolean given in on line 40
Warning: imagesy() expects parameter 1 to be resource, boolean given in on line 41
我怎样才能解决这个问题?并注意 png 文件是一个字符串,我无法将其作为 url