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

后端 未结 8 2214
走了就别回头了
走了就别回头了 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:37

    I just made an imageCrop and Upload feature with

    https://www.npmjs.com/package/react-image-crop

    to get the ImagePreview ( the cropped image rendering in a canvas)

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob

    canvas.toBlob(function(blob){...}, 'image/jpeg', 0.95);
    

    I prefer sending data in blob with content type image/jpeg rather than toDataURL ( a huge base64 string`

    My implementation for uploading to Azure Blob using SAS URL

    axios.post(azure_sas_url, image_in_blob, {
       headers: {
          'x-ms-blob-type': 'BlockBlob',
          'Content-Type': 'image/jpeg'
       }
    })
    

提交回复
热议问题