![](/img/trans.png)
[英]How do you pass PHP string to Javascript/JQuery to use in function?
[英]How do you use a png string in the PHP function imagecreatefromstring?
我有一个名为$ 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文件是一个字符串,我无法将其作为网址获取
检查一下。 您将对“ imagecreatefromstring”函数有一个了解。 http://php.net/manual/zh/function.imagecreatefromstring.php
可能会迟到,但您可以尝试:
$image = imagecreatefromstring(file_get_contents($png_file));
$width = imagesx($image);
$height = imagesy($image);
注意: file_get_contents
部分。
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.