Skip to content

Instantly share code, notes, and snippets.

@addorange
Created June 19, 2013 09:32
Show Gist options
  • Save addorange/5813017 to your computer and use it in GitHub Desktop.
Save addorange/5813017 to your computer and use it in GitHub Desktop.
draw image on canvas and deliver result as base64 to a textarea
<html>
<canvas width='400' height='450' id='canvas'>Ihre Browser ist nicht HTML5-tauglich. Bitte nutzen Sie einen aktuellen Browser.</canvas>
<textarea cols="40" rows="8" name="img" id="result"></textarea>
<script type="text/javascript">
var canvas = document.getElementById('canvas');
var ctxCanvas = canvas.getContext('2d');
var myImage = new Image();
myImage.src = 'path/to/image';
myImage.onload = function(){
ctxCanvas.drawImage(myImage, 100, 100);
document.getElementById('result').innerHTML = canvas.toDataURL();
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment