Created
May 2, 2014 04:57
-
-
Save marcelcaraciolo/99c5b91bf2924c7a74f8 to your computer and use it in GitHub Desktop.
Simple app
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
$("#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