Last active
July 22, 2017 13:04
-
-
Save masterk63/83fd48c40274d160fef28b4278dd559e to your computer and use it in GitHub Desktop.
Escribir en imagen, con cancas
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
var canvas = document.getElementById('canvas'), | |
ctx = canvas.getContext('2d'); | |
canvas.width = $('img').width(); | |
canvas.crossOrigin = "Anonymous"; | |
canvas.height = $('img').height(); | |
ctx.drawImage($('img').get(0), 0, 0); | |
ctx.font = "36pt Verdana"; | |
$(document).on('input','#inp',function(){ | |
//redraw image | |
ctx.clearRect(0,0,canvas.width,canvas.height); | |
ctx.drawImage($('img').get(0), 0, 0); | |
//refill text | |
ctx.fillStyle = "red"; | |
ctx.fillText($(this).val(),40,80); | |
ctx.fillStyle = "blue"; | |
ctx.fillText('kevin',40,120); | |
}); | |
$('button').click(function(){ | |
console.log(ctx.getImageData(50, 50, 100, 100)); | |
}); | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
<form> | |
<img style="display:none" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTsEbEB4kEMHt3WJ13HpZE16hJ3iKrE8ugnErvyln7oNPDma48U" crossorigin="anonymous"/> | |
<input type="text" id="inp"/> | |
<button type="submit">Save</button> | |
</form> | |
<canvas id="canvas" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment