Decoding a canvas todataURL

前端 未结 4 1209
深忆病人
深忆病人 2020-12-07 03:06

I\'m having difficulty using data created with canvas\'s todataurl() method. Currently my code sends the resulting data to my php server which uses the file_put_contents() m

4条回答
  •  不知归路
    2020-12-07 03:17

    It seems you have to get rid of the header that is prepended to the image data by the toDataURL() function. On the client side you can strip off the header like this:

    ..
    var data=canvas.toDataURL();
    var output=data.replace(/^data:image\/(png|jpg);base64,/, "");
    // now send "output" to the server
    ..
    

    On the server side use this:

    
    

提交回复
热议问题