-
Notifications
You must be signed in to change notification settings - Fork 0
/
tintscan.js
44 lines (31 loc) · 1023 Bytes
/
tintscan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(function ($) {
$.fn.tint = function (params) {
this.each(function () {
var c = document.createElement('canvas');
var ctx = c.getContext('2d');
c.width = $(this).width();
c.height =$(this).height();
f = new Image();
f.src = $(this).prop("src");
f.crossOrigin = 'anonymous';
ctx.drawImage(f,0,0,c.width,c.height);
var buffer = ctx.getImageData(0, 0, c.width, c.height),
data = buffer.data,
len = data.length;
for(i=0; i < len; i += 4) {
data[i] = 0;
data[i + 1] = data[i + 1] ;
data[i + 2] = 0;
}
ctx.putImageData(buffer, 0, 0);
for (i = 0; i < c.height; i += 3)
{
ctx.fillStyle = '#000';
ctx.globalAlpha = 1;
ctx.globalCompositeOperation = "overlay";
ctx.fillRect(0, i, c.width, 5);
}
var jpg = c.toDataURL("image/jpeg", 1.0);
$(this).prop("src",jpg);
})}
})(jQuery);