How to save a html5 Canvas.toDataURl string as a png on a php backend

前端 未结 1 1097
深忆病人
深忆病人 2020-12-18 10:18

After converting my canvas to a an image source using

 canvas.toDataURL(\"image/png\");

and passing it to a php file, how do I save it as

相关标签:
1条回答
  • 2020-12-18 10:58

    It's actually very simple, if you have allow-url-fopen enabled. PHP supports the data: URL scheme then, and automatically decodes base64 and urlencoding.

    preg_match('#^data:[\w/]+(;[\w=]+)*,[\w+/=%]+$#', $data=$_POST["dataU"])
    and
    copy($data, "output.png");
    

    But you could also just extract the part after the , and manually base64_decode() it.

    0 讨论(0)
提交回复
热议问题