doulu8446 2014-05-03 04:30
浏览 253
已采纳

如何将画布图像保存到服务器

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>';
  • 写回答

1条回答 默认 最新

  • dqrnsg6439 2014-05-03 06:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题