Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.