Created
April 23, 2014 21:33
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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