I am showing a screenshot with html2canvas 0.4.0 and want to save it as an image on my web server.
For this, I wrote the following function:
Javascript
function screenShot(id) { html2canvas(id, { proxy: "https://html2canvas.appspot.com/query", onrendered: function(canvas) { $('body').append(canvas); // This works perfect... var img = canvas.toDataURL("image/png"); var output = img.replace(/^data:image\/(png|jpg);base64,/, ""); var Parameters = "image=" + output + "&filedir=" + cur_path; $.ajax({ type: "POST", url: "inc/saveJPG.php", data: Parameters, success : function(data) { console.log(data); } }).done(function() { }); } }); }
saveJPG.php
<?php $image = $_POST['image']; $filedir = $_POST['filedir']; $name = time(); $decoded = base64_decode($image); file_put_contents($filedir . "/" . $name . ".png", $decoded, LOCK_EX); echo $name; ?>
After rendering the canvas, I can perfectly add it to the body of the HTML, but saving it on my server leads to a damaged (?) File.
I can read sizes in IrvanView, but is the image transparent / empty? The file is approximately 2.076 KB in size. So it really is not empty.
I also tried this with JPEG, and this leads to a damaged file, and IrfanView says something like "dummy marker length".
The screenshot is 650x9633. How much data is there for the POST method?
source share