It is posible to send a canvas image to server format JPG? I tried with var dataURL = canvas.toDataURL('image/jpg') but did not work. Can someone help me please? Thanks
1 Answer
First, you have to convert your image to base64 format using Javascript:
var canvas = document.getElementById("canvas"); var data = canvas.toDataURL("image/jpeg"); And send this data to your PHP server using ajax for example. Then, in your PHP file, you just have to use this code to convert the base64 data to an image:
file_put_contents("myimage.jpg", base64_decode(explode(",", $_GET['data'])[1])); That's all !
4 Comments
user3651419
Thanks Lucas,I've already done that, but I want JPG format send to server.. is not possible?
Lucas Willems
Sorry, I didn't see you wanted the JPEG format. I updated my answer.
Maurice Perry
Perhaps you should remove the heading 'data:image/jpeg,' on either side
Lucas Willems
If my answer could help you, you can validate it.