Most of the time, we need to save the picture data on the Web or the picture inside the canvas to the server. The HTML5 already provides the available interfaces.
Canvas's Todataurl method, you can export canvas data on canvas to a string format. We just need to transfer the string to the server.
What if the image is an IMG tag?
Very simply, Canvas provides the DrawImage method for drawing img or other canvas data onto your canvas.
Below, let's look at the client's code:
var cc = window.document.getElementById ("Egretcanvas"), var cc2 = document.createelement ("canvas"); Cc2.setattribute (" Width "," "Cc2.setattribute"); var ctx = Cc2.getcontext ("2d"), Ctx.drawimage (cc, 0, 0, 320, 514);
var imgdata:string = cc2["Todataurl"] ();
So the exported string, which contains the prefix " data:image/png;base64," so we need to remove this prefix
Then pass the string to the server, where we choose to use the PHP language to receive the data and save the image.
$imgurl = Str_replace (', ' + ', $_request[' image ');
First, replace the space in the string with the "+" sign.
$savePath = ". /images/123.png "; $image = Base64_decode ($image); File_put_contents ($savePath, $image);
After PHP gets the data, it needs to be Base64 decoded before it can be saved as a picture.
The above describes the HTML upload image data to the server, PHP received save pictures, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.