Question

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>';
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top