I want to save the image that is taken from the html2canvas.
Here is code but this doen't work.
This code take the screen shot of the div mydiv and then save it.
<html>
<head>
<script src="jquery.js" ></script>
<script src="html2canvas.js" ></script>
<script src="jquery.plugin.html2canvas.js" ></script>
<script>
$(document).ready(function(){
$('button').click(function(){
elem = $('#mydiv');
html2canvas(elem, {
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png");
var output = img.replace(/^data:image\/(png|jpg);base64,/, "");
var output = encodeURIComponent(img);
var cur_path = 'myfolder';
var Parameters = "image=" + output + "&filedir=" + cur_path;
$.ajax({
type: "POST",
url: "savePNG.php",
data: Parameters
});
}
});
});
});
</script>
</head>
<body>
<div id="mydiv">
<h1>Here is some content</h1>
</div>
<button>click</button>
</body>
</html>
savePNG.php
<?php
$image = $_POST['image'];
$filedir = $_POST['filedir'];
$name = time();
$image = str_replace('data:image/png;base64,', '', $image);
$decoded = base64_decode($image);
file_put_contents($filedir . "/" . $name . ".png", $decoded, LOCK_EX);
echo $image;
?>
This is not work. what is the problem with that code. please help me.