简体   繁体   English

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

[英]how can I save canvas image to the server

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. 我知道有很多与此有关的问题,但是目前我正尝试将画布图像保存到服务器,最近我启动了javascript,因此遇到了很多问题。 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. 但是因为图像是在画布上用动态src生成的,所以我无法用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 我的PHP代码

    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>';

hey @mimi maybe it's better you upload base-64 form of the image as string and convert it to PNG on server-side. 嘿@mimi最好将图像的base-64形式上传为字符串,然后在服务器端将其转换为PNG。 but still you can upload the image from client-side but i prefer to upload base-64 form of it. 但您仍然可以从客户端上传图像,但我更喜欢以base-64格式上传图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM