...

View Full Version : Read Pixel?



Trinithis
05-22-2009, 01:08 AM
Is it possible to read a pixel from an image with firefox's javascript (with chrome access)? I want to make a greasemonkey script that operates on a (very simple) captcha. If reading pixels is not possible in javascript, would anyone know if it is possible to have greasemonkey communicate information to and from something that can solve such a problem (eg: java)?

rnd me
05-22-2009, 02:36 AM
in firefox, yes you can.
you don't need anything but the canvas element.

it provides an array of Numbers(0-255), where every 4 Numbers = 1 RGBA pixel.

the image editor in my sig uses this for some of the filters like edge detection, some of the grayscale conversions, sharpen, etc.

all the filters are functions, so viewing the source will show you several examples of using this pixel data.


for example:



// image loader:
function loadImg(srcImg) {
var img = new Image();
img.onload = function(){
var h=img.height,
w=img.width;
canvas.width=w;
canvas.height=h;
canvas.style.height=h+"px";
canvas.style.width=w+"px";

ctx = canvas.getContext('2d');
ctx.drawImage(img,0, 0,w,h);
tid=ctx.getImageData(0, 0, w, h);
mx=tid.data.length;
}//end onload

img.src= srcImg;

}//end loadImg


function quickBW( ) {
var ctx = canvas.getContext('2d'),
tid=ctx.getImageData(0, 0, canvas.width, canvas.height),
mx=tid.data.length,
t=tid.data;

for(var z=0; z< mx;z+=4){
var col=parseInt( (t[z]+t[z+1]+t[z+2]) / 3 )
t[z]=col;
t[z+1]=col;
t[z+2]=col;
}
ctx.putImageData(t, 0, 0, w, h);
}//end desat


canvas is a global, the canvas element via getElementById...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum