保存图片时遇到问题。
主要问题是我在Android 4.1.2(三星手机)上保存图像时。
在Internet Explorer或Chrome上运行时没有问题。
(另请查看谷歌的解决方案,但没有找到任何可能有用的信息,即http://comments.gmane.org/gmane.comp.graphics.png.devel/3612)
在javascript中我对图像进行了一些操作:旋转它,按尺寸缩小它:
mystr = myCanvas.toDataURL("image/png");
字符串类似于:
数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAYAAAC ZpjcAAAABHNCSVQICAgIfAhkiAAABZ9JREFUeJzswQENAAAAwqD3T20PBxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
保存图像时(通过'POST'方法将其发送到php)。我有一个例外:
<br />
<b>Warning</b>: imagecreatefrompng(): gd-png: fatal libpng error: IHDR: CRC error in <b>*********</b> on line <b>105</b><br />
<br />
<b>Warning</b>: imagecreatefrompng(): gd-png error: setjmp returns error condition in <b>*********</b> on line <b>105</b><br />
<br />
<b>Warning</b>: imagecreatefrompng(): 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAYAAAC ZpjcAAAABHNCSVQICAgIfAhkiAAABZ9JREFUeJzswQENAAAAwqD3T20PBxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA in <b>/home/********/saveImage.php</b> on line <b>105</b><br />
<br />
<b>Warning</b>: imagesx() expects parameter 1 to be resource, boolean given in <b>/home/*********************</b> on line <b>135</b><br />
<br />
<b>Warning</b>: imagesy() expects parameter 1 to be resource, boolean given in <b>/home/*********************</b> on line <b>136</b><br />
<br />
<b>Warning</b>: imagecreatetruecolor(): Invalid image dimensions in <b>/home/*********************</b> on line <b>176</b><br />
<br />
<b>Warning</b>: imagecopyresized() expects parameter 1 to be resource, boolean given in <b>/home/*********************</b> on line <b>183</b><br />
<br />
<b>Warning</b>: imagerotate() expects parameter 1 to be resource, boolean given in <b>/home/*********************</b> on line <b>211</b><br />
有时,我还有其他错误,即:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>501 Method Not Implemented</title>
</head><body>
<h1>Method Not Implemented</h1>
<p>GET to /saveImage.php not supported.<br />
</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>
$.ajax({
url : "saveImage.php",
type: "POST",
dataType: "html",
data: {
'scale': 1
'top': 0,
'left': 0,
'ext': picExt,
'src': s // ***** the main string for the image - about 300K ******
},
timeout: 30000
}).success(function (result) {
// code doesn't reach here
s = result;
}).fail(function (jqXHR, textStatus) {
// code reach here
if (textStatus === "timeout") {
// ****** code doesn't reach here
} else {
// ******* code reach here
}
// ***** code reach here
});
我没有“GET”方法,但据我所知,对于javascript我做了如下,也有错误,但更少......
xmlhttp.open("POST", "saveImage.php", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
...
xmlhttp.send("&scale=" + scaleRatio +
"&top=0" +
"&left=0" +
// ...
"&src=" + encodeURIComponent(s)); // **** src is the 300K string send to server.
并且在服务器站点上我不知道我是否将解码图像300K字符串,而不是:
$imagebin = (urldecode)((string)$_POST['src']); // is decode necessary?
正如我猜测的那样,我调用ajax的方式不正确(可能它有时解码字符串,有时不解码?)
...有时我得到一个错误(我一次又一次没有得到同样的错误 - 似乎随机解决了):
HTTP 403
我得到了php版本5.4.21。 gd版本:捆绑(2.1.0兼容)
可能是什么问题?
谢谢:)
答案 0 :(得分:1)
在调查此案时,有两个主要问题导致错误:
所以,我应该在客户端编码字符串,即使我发送字符串&#39; POST&#39;方法,即如下代码(注意带星号的行并调用函数 encodeURIComponent(s))。
$.ajax({
url : "saveImage.php",
type: "POST",
dataType: "html",
data: {
'scale': 1
'top': 0,
'left': 0,
'ext': picExt,
'src': encodeURIComponent(s) /*********/
},
timeout: 30000
}).success(function (result) {
// code doesn't reach here
s = result;
}).fail(function (jqXHR, textStatus) {
// ******* code doesn't reach here any more ******
if (textStatus === "timeout") {
// ****** code doesn't reach here
} else {
// ******* code doesn't reach here any more ******
}
// ******* code doesn't reach here any more ******
});
这就是为什么会出现错误,例如:
imagecreatefrompng():gd-png:致命的libpng错误:IHDR:CRC错误......
和
不支持Gets to /saveImage.php。
首先,可以进行一些配置以获得子状态代码,如http://en.wikipedia.org/wiki/HTTP_403
中所述其次,403.9的错误表明打开的会话太多了, 所以我通过php函数检查了会话的位置:session_save_path(),看到很多文件以sess_开头 - 这些文件是会话。
当session.gc_maxlifetime声明时,会话过期了很长时间。
在我的网站上,会话在1小时半后过期。
所以,垃圾收集器应该删除会话文件 - 这在我的网站上运行不好,所以我有很多会话文件 - 导致403错误。
我做的是,我只是删除了会话文件。
问题解决了。
谢谢:)