PHP turns Dataurl into image Image method
Using canvas generated pictures, is using Dataurl, PHP can not directly save the File_put_contents method to the local computer, need to do a bit of transcoding.
Picture Dataurl as follows
$imgstr = ' data:image/png;base64,ivborw0kggoaaaansuheugaaaauaaaafcayaaacnbyblaaaaheleqvqi12p4//8/ w38giaxdibke0dhxgljnbaao9txl0y4ohwaaaabjru5erkjggg== ';
Method One:
By just extracting the data needed for dataurl storage, and then showing it directly on the page
if (!preg_match) ('/data: ([^;] *); Base64, (. *)/', $IMGSTR, $matches)) {
die ("error");
}
$content = Base64_decode ($matches [2]);
Header (' Content-type: '. $matches [1]);
Header (' Content-length: ' strlen ($content));
echo $content;
Die
Method Two:
If you just want to save the picture to the local, you can use the substr and Strpos methods
$imgdata = substr ($imgstr, Strpos ($imgstr, ",") + 1);
$decodedData = Base64_decode ($imgdata);
File_put_contents (' 11.png ', $decodedData);
Thank you for reading, I hope to help you, thank you for your support for this site!