I'm adding image to canvas and then trying to add text on the top of the image. Text is binded to text input. The problem is that when I type text in the field, instead of redrawing, it's duplicate itself.
My directive:
.directive('memeimage', function () {
return {
restrict: 'A',
link: function (scope, el, attrs) {
scope.upperText = "";
scope.fontsize = 50;
scope.drawCanvas = function () {
var canvas = el[0];
var context = canvas.getContext("2d");
context.font = scope.fontsize + "px Impact";
context.fillStyle = 'white';
context.strokeStyle = 'black';
var x = canvas.width / 2;
var y = canvas.height / 6;
context.textAlign = 'center';
context.fillText(scope.upperText.toUpperCase(), x, y);
context.lineWidth = 2;
context.strokeText(scope.upperText.toUpperCase(), x, y);
};
}
}
});
Here's fiddle: http://jsfiddle.net/HB7LU/5085/
How to avoid this and to not duplicate text? Clearing canvas isn't way to go, because I'have also using image on same canvas.
Thanks