title: Error when saving image
body: <p>I have problem when saving image.</p>
  
  <p>The major problem is when I am saving the image on Android 4.1.2 (Samsung phone).</p>
  
  <p>I got no problem when running on internet explorer or chrome.</p>
  
  <p>(Also look at google for solutions, but found nothing that may help, i.e. <a href="http://comments.gmane.org/gmane.comp.graphics.png.devel/3612" rel="nofollow">http://comments.gmane.org/gmane.comp.graphics.png.devel/3612</a>)</p>
  
  <p>In javascript after I did some manipulations on image: rotate it, shrinking it by size I do:</p>
  
  <pre><code>mystr = myCanvas.toDataURL("image/png");
  </code></pre>
  
  <p>the string is something like:</p>
  
  <blockquote>
    <p>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAYAAAC
    ZpjcAAAABHNCSVQICAgIfAhkiAAABZ9JREFUeJzswQENAAAAwqD3T20PBxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p>
  </blockquote>
  
  <p>when saving the image (sending it to php by 'POST' method). I got an exceptions:</p>
  
  <pre><code>&lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagecreatefrompng(): gd-png:  fatal libpng error: IHDR: CRC error in &lt;b&gt;*********&lt;/b&gt; on line &lt;b&gt;105&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagecreatefrompng(): gd-png error: setjmp returns error condition in &lt;b&gt;*********&lt;/b&gt; on line &lt;b&gt;105&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagecreatefrompng(): 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAJYCAYAAAC ZpjcAAAABHNCSVQICAgIfAhkiAAABZ9JREFUeJzswQENAAAAwqD3T20PBxQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA in &lt;b&gt;/home/********/saveImage.php&lt;/b&gt; on line &lt;b&gt;105&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagesx() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/*********************&lt;/b&gt; on line &lt;b&gt;135&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagesy() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/*********************&lt;/b&gt; on line &lt;b&gt;136&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagecreatetruecolor(): Invalid image dimensions in &lt;b&gt;/home/*********************&lt;/b&gt; on line &lt;b&gt;176&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagecopyresized() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/*********************&lt;/b&gt; on line &lt;b&gt;183&lt;/b&gt;&lt;br /&gt;
  &lt;br /&gt;
  &lt;b&gt;Warning&lt;/b&gt;:  imagerotate() expects parameter 1 to be resource, boolean given in &lt;b&gt;/home/*********************&lt;/b&gt; on line &lt;b&gt;211&lt;/b&gt;&lt;br /&gt;
  </code></pre>
  
  <p>Sometimes, I got other errors, i.e:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;501 Method Not Implemented&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Method Not Implemented&lt;/h1&gt;
  &lt;p&gt;GET to /saveImage.php not supported.&lt;br /&gt;
  &lt;/p&gt;
  &lt;p&gt;Additionally, a 404 Not Found
  error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <h1>I think the above error is related to the way I call ajax in javascript:</h1>
  
  <pre><code>$.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
  });
  </code></pre>
  
  <p>I don't have "GET" method, but as I know that for javascript I did as following, there was also errors, but much less ...</p>
  
  <pre><code>    xmlhttp.open("POST", "saveImage.php", true);
      xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  ...
          xmlhttp.send("&amp;scale=" + scaleRatio +
              "&amp;top=0" +
              "&amp;left=0" + 
  // ...
              "&amp;src=" + encodeURIComponent(s)); // **** src is the 300K string send to server.
  </code></pre>
  
  <p>and on server site I don't know if I shall decode the image 300K string, or not:</p>
  
  <pre><code>$imagebin = (urldecode)((string)$_POST['src']); // is decode necessary?
  </code></pre>
  
  <p>As I can guess, the way I call ajax is not correct (May it sometimes decode the string, and sometimes not?)</p>
  
  <p>... and sometimes I got an error (I not got the same error again and again - it seems to be resolved randomly):</p>
  
  <blockquote>
    <p>HTTP 403</p>
  </blockquote>
  
  <p>I got php version 5.4.21.
  gd version: bundled (2.1.0 compatible)</p>
  
  <p>What may be the problem?</p>
  
  <p>Thanks :)</p>