Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created May 2, 2014 04:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelcaraciolo/99c5b91bf2924c7a74f8 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/99c5b91bf2924c7a74f8 to your computer and use it in GitHub Desktop.
Simple app
$("#send").click(function(e) {
// convert canvas to data url
var img = canvas.toDataURL();
// make request to server
$.post("/", {img: img, n: n}, function() {
// when request is finished, redirect to homepage
window.location.replace("/");
})
return false;
});
app.post('/', function(req, res) {
// extract arguments from request
var img = req.body.img
, n = req.body.n;
// extract image data from img
var data = img.replace(/^data:image\/\w+;base64,/, "");
// write image to a binary file
var buf = new Buffer(data, 'base64');
var f = "numbers/" + uuid.v1() + "_digit_" + n + ".png";
fs.writeFile(f, buf);
// redirect the user to the homepage (gives them a new number to input)
res.redirect("/");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment