1

I know there is a lot of questions regarding this but currently I am trying to save canvas image to server, I recently start javascript so I meet lots of problem. I write image editor which allow user to save the canvas as an image file to server after editing is finished. but because image produce with dynamic src in canvas I cant save it with php. can any one help me with this problem??

my code

html2canvas([document.getElementById('dadycool')], {
     onrendered: function (canvas) {
               var data = canvas.toDataURL('image/png');
               var image = new Image();
               image.src ='data:image/jpeg;base64,""';
               document.getElementById('imagec').appendChild(image);
             $.ajax({
      type: "POST",
      url: "resize.php",
      data: { 
         imgBase64: dataURL
      }
      }).done(function(o) {
      console.log('saved'); 

         }); 
        }

my php code

    echo '<div class="wifix">';
    echo '<div class="dadycool" id="dadycool">';
    echo '<div class="fixx" align="center"><img class="ui-widget-content"  id="resizable" src="uploads/'.$ThumbPrefix.$NewImageName.'" alt="Thumbnail">';
    echo '</div>';
    echo '</div>';
    echo '</div>';
    echo '<div id="imagec"></div>';
mkafiyan
  • 944
  • 2
  • 9
  • 31

1 Answers1

0

hey @mimi maybe it's better you upload base-64 form of the image as string and convert it to PNG on server-side. but still you can upload the image from client-side but i prefer to upload base-64 form of it.

Omid Gharib
  • 301
  • 1
  • 9
  • 26
  • I cant understand what u said very well. u mean that first I upload as base64 and then convert it to png? but how ???!!! – mkafiyan May 03 '14 at 06:38
  • @mimi yes upload the string (base64 of the canvas) to the server-side – Omid Gharib May 03 '14 at 06:44
  • @mimi look at this [question](http://stackoverflow.com/questions/13198131/how-to-save-a-html5-canvas-as-image-on-a-server) it's similar to your question – Omid Gharib May 03 '14 at 07:04