Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created April 23, 2014 21:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nebiros/11233233 to your computer and use it in GitHub Desktop.
takes a screenshot from some html element with html2canvas.js and save it to server with PHP.
html2canvas(document.getElementById("an_element_id"), {
onrendered: function(canvas) {
var img = canvas.toDataURL("image/png");
$.post("http://blah.com", {image_data: img}, function (data, textStatus, jqXHR) {
console.log(arguments);
});
}
});
<?php
$imageData = $_POST["image_data"];
if (empty($imageData)) {
header($_SERVER["SERVER_PROTOCOL"] . " 500 Internal Server Error", true, 500); exit();
}
$imageBase64 = str_replace("data:image/png;base64,", "", $imageData);
$imageBin = base64_decode($imageBase64);
file_put_contents(dirname(__FILE__) . "/anImage.png", $imageBin, LOCK_EX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment