1

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 1

2

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 !

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Lucas,I've already done that, but I want JPG format send to server.. is not possible?
Sorry, I didn't see you wanted the JPEG format. I updated my answer.
Perhaps you should remove the heading 'data:image/jpeg,' on either side
If my answer could help you, you can validate it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.