I am having a problem saving a canvas image to my server. I have tried multiple things and the only thing that seems to work right now is using one suggestion I found looking around which was to fill a hidden text field in a form and submit it to my php page that can take the post and convert it and save it on the server. While this does work, it is only posting 1/8th of the image.
When I check the toDataURL() contents it is the same amount of data that is passed on to the PHP page so I'm not sure where the image is getting chopped up and the image size only ends up about 380kb.
Here is what I have:
Javascript:
var canvas = document.getElementById("myCanvas");
var image = canvas.toDataURL();
document.getElementById("savecarddata").value = image;
PHP
$upload_dir = 'mydirectory';
$img = $_POST['savecarddata'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = $upload_dir.rand().".png";
$success = file_put_contents($file, $data);
This does save the image but only the top of it. I've tried ajax but I can't seem to get it to work right so this was the next best solution for me. I would love any help!
Thanks in advance!