html5 canvas input,javascript - HTML5 Canvas Image Draw with input text - Stack Overflow

yftCK.pngI am new to Canvas and I have a task where I have an input box to input a text. then I upload an image.When the image is displayed, it should have the text repeated in the background.

So far I have been able to upload the image and slightly grey scale it, but I do not know how to to use the text to be repeate din the background

It would be great if someone could point me in the direction of what to do next.-Thanks

my code so far:

document.addEventListener('DOMContentLoaded', function(){

var canvas = document.getElementById('canvas');

var context = canvas.getContext('2d');

var source = document.getElementById('fileupload');

source.addEventListener('change',handleImage,false);

function handleImage(e){

var reader = new FileReader();

reader.onload = function(event){

var img = new Image();

img.onload = function(){

context.drawImage(img,0,0);

grayScale(context, canvas);

}

img.src = event.target.result;

}

reader.readAsDataURL(e.target.files[0]);

}

function grayScale(context, canvas) {

var imgData = context.getImageData(0, 0, canvas.width, canvas.height);

var pixels = imgData.data;

for (var i = 0, n = pixels.length; i < n; i += 4) {

pixels[i]+=20;

var grayscale = (pixels[i*4] + pixels[i*4+1] + pixels[i*4+2]) /3;

pixels[i*4 ] = grayscale; // red

pixels[i*4+1] = grayscale+30; // green

pixels[i*4+2] = grayscale; // blue

// pixels[i+3] = 0.5; // is alpha

}

//redraw the image in black & white

context.putImageData(imgData, 0, 0);

}

})

Background

Select file:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值