Created
May 17, 2012 17:04
-
-
Save geta6/2720222 to your computer and use it in GitHub Desktop.
卑猥なGoogleロゴをモザイクにします Firefoxの場合はアドレスバーでなくブックマーク登録からご利用ください
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
javascript:(function(){var g=function(c){return document.getElementById(c?"hplogo":"lga")},g={i:g(0),d:g(1),w:g(1).naturalWidth,h:g(1).naturalHeight},d=document.createElement("canvas"),o=d.getContext("2d"),a=g.i.querySelector("a"),e=5;d.setAttribute("width",g.w+"px");d.setAttribute("height",g.h+"px");d.setAttribute("style",g.d.getAttribute("style"));o.drawImage(g.d,0,0);a.innerHTML="";a.appendChild(d);for(var k=0;k<g.h;k+=e){var f=(e<=g.h-k)?e:g.h-k;for(var l=0;l<g.w;l+=e){var m=(e<=g.w-l)?e:g.w-l,b=[0,0,0],n=o.getImageData(l,k,m,f).data;for(var j=0;j<n.length;j+=4){b[0]+=n[j];b[1]+=n[j+1];b[2]+=n[j+2]}var i=n.length/4;b[0]=Math.floor(b[0]/i);b[1]=Math.floor(b[1]/i);b[2]=Math.floor(b[2]/i);o.clearRect(l,k,m,f);o.fillStyle="rgb("+b.join(",")+")";o.fillRect(l,k,m,f)}}}()); |
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
// yuicompressor moshroom.js | pbcopy | |
javascript: | |
(function () { | |
var tar = function (a) { return document.getElementById(a?'hplogo':'lga') }, | |
tar = { i : tar(0), d : tar(1), w : tar(1).naturalWidth, h : tar(1).naturalHeight }, | |
cvs = document.createElement('canvas'), | |
ctx = cvs.getContext('2d'), | |
sub = tar.i.querySelector('a'), | |
box = 5; | |
cvs.setAttribute('width', tar.w + 'px'); | |
cvs.setAttribute('height', tar.h + 'px'); | |
cvs.setAttribute('style', tar.d.getAttribute('style')); | |
ctx.drawImage(tar.d, 0, 0); | |
sub.innerHTML = ''; | |
sub.appendChild(cvs); | |
for (var y = 0; y < tar.h; y += box) { | |
var h = (box <= tar.h - y) ? box : tar.h - y; | |
for (var x = 0; x < tar.w; x += box) { | |
var w = (box <= tar.w - x) ? box : tar.w - x, | |
col = [0, 0, 0], | |
dat = ctx.getImageData(x, y, w, h).data; | |
for (var z = 0; z < dat.length; z += 4) { | |
col[0] += dat[z]; | |
col[1] += dat[z+1]; | |
col[2] += dat[z+2]; | |
} | |
var c = dat.length/4; | |
col[0] = Math.floor(col[0] / c); | |
col[1] = Math.floor(col[1] / c); | |
col[2] = Math.floor(col[2] / c); | |
ctx.clearRect(x, y, w, h); | |
ctx.fillStyle = 'rgb(' + col.join(',') + ')'; | |
ctx.fillRect(x, y, w, h); | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment