How to save an HTML5 Canvas as an image on a server?

后端 未结 8 2240
走了就别回头了
走了就别回头了 2020-11-21 23:50

I\'m working on a generative art project where I would like to allow users to save the resulting images from an algorithm. The general idea is:

  • Create an image
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 00:42

    Send canvas image to PHP:

    var photo = canvas.toDataURL('image/jpeg');                
    $.ajax({
      method: 'POST',
      url: 'photo_upload.php',
      data: {
        photo: photo
      }
    });
    

    Here's PHP script:
    photo_upload.php

    
    

提交回复
热议问题