-
Notifications
You must be signed in to change notification settings - Fork 5
/
Editr.js
4 lines (4 loc) · 1.67 KB
/
Editr.js
1
2
3
4
var Editr=function(f){var h=document.createElement("canvas"),b,d;h.setAttribute("width",f.width);h.setAttribute("height",f.height);b=h.getContext("2d");b.drawImage(f,0,0);d=b.getImageData(0,0,f.width,f.height);b.grayScale=function(){var a=d.data,e=a.length,c,g;for(c=0;c<e;c+=4)g=(a[c]+a[c+1]+a[c+2])/3,d.data[c]=g,d.data[c+1]=g,d.data[c+2]=g;b.putImageData(d,0,0);return b};b.sepia=function(){var a=d.data,e=a.length,c,g,f,h;for(c=0;c<e;c+=4)g=a[c]*0.393+a[c+1]*0.769+a[c+2]*0.189,f=a[c]*0.349+a[c+1]*
0.686+a[c+2]*0.168,h=a[c]*0.272+a[c+1]*0.534+a[c+2]*0.131,d.data[c]=g,d.data[c+1]=f,d.data[c+2]=h;b.putImageData(d,0,0);return b};b.invert=function(){var a=d.data,e=a.length,c;for(c=0;c<e;c+=4)d.data[c]=255-a[c],d.data[c+1]=255-a[c+1],d.data[c+2]=255-a[c+2];b.putImageData(d,0,0);return b};b.monoRed=function(){var a=d.data.length,e;for(e=0;e<a;e+=4)d.data[e+1]=0,d.data[e+2]=0;b.putImageData(d,0,0);return b};b.monoGreen=function(){var a=d.data.length,e;for(e=0;e<a;e+=4)d.data[e]=0,d.data[e+2]=0;b.putImageData(d,
0,0);return b};b.monoBlue=function(){var a=d.data.length,e;for(e=0;e<a;e+=4)d.data[e]=0,d.data[e+1]=0;b.putImageData(d,0,0);return b};b.rotate180=function(){var a=document.createElement("img");a.setAttribute("src",b.canvas.toDataURL("image/png"));b.translate(a.width-1,a.height-1);b.rotate(Math.PI);b.drawImage(a,0,0,a.width,a.height);return b};b.flipHorizontal=function(){var a=document.createElement("img");a.setAttribute("src",b.canvas.toDataURL("image/png"));b.translate(a.width,0);b.scale(-1,1);b.drawImage(a,
0,0,a.width,a.height);return b};b.replace=function(){f.setAttribute("src",b.canvas.toDataURL("image/png"))};b.dataURL=function(){return b.canvas.toDataURL("image/png")};return b};