Reputation: 13
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
Upvotes: 1
Views: 2000
Reputation: 7063
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 !
Upvotes: 2