This article mainly introduces the PHP will dataurl to the image image method of the relevant data, here provides two methods and implementation methods, the need for friends can refer to the following
PHP convert Dataurl to image Image method
Using canvas generated pictures, is using Dataurl, PHP can not be saved directly through the File_put_contents method to the local computer, need to do a transcoding.
Picture Dataurl as follows
$imgstr = ' data:image/png;base64,ivborw0kggoaaaansuheugaaaauaaaafcayaaacnbyblaaaaheleqvqi12p4//8/ w38giaxdibke0dhxgljnbaao9txl0y4ohwaaaabjru5erkjggg== ';
Method One:
Extract the data needed for the Dataurl store via regular, then show 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;d ie;
Method Two:
If you just want to save the image locally, you can use the substr and Strpos methods
$imgdata = substr ($imgstr, Strpos ($imgstr, ",") + 1); $decodedData = Base64_decode ($imgdata); File_put_contents (' 11.png ') , $decodedData);
Summary: The above is the entire content of this article, I hope to be able to help you learn.