2

I am looking to explore the feasibility of writing a simple greasemonkey script / chrome userscript to convert all the images loaded in the browser window to grayscale/black and white. The ultimate goal is to perform more complex image processing. What I would like to do is write a script to add an onload function containing something like the following:

var images = document.getElementsByTagName("img");
for (var i = 0; i < images.length; ++i) {
    filter(images[i]);
}

I know this sort of thing can be done on the same domain the page is loaded from (i.e. built into the website ui logic), but from what I've read and some early experimentation I've done (with html5 canvases), I'm wondering if it is feasible to perform from the client side via plugin because of crossdomain problems and other issues. Can anyone tell me if this is a feasible project, are there any tutorials or similar projects I might use as a reference?

Thanks.

S.C.
  • 1,152
  • 8
  • 13
  • A reference to another thread that makes me think that this might not be possible to implement as a simple client-side script: http://stackoverflow.com/questions/8128118/get-security-error-when-saving-canvas-object-into-an-image – S.C. Mar 18 '12 at 22:08

1 Answers1

2

I would say that if you have a purpose for this script that it would be feasable to make the userscript.

I would recommend you look at this link, because I imagine it will help you tremendously.

Bigandrewgold
  • 835
  • 3
  • 12
  • 19
  • Thanks for the response. However, one of the reasons I ask about the feasibility of such a project is when I implement the method described in the link, I get the following two errors in my debugging window and the script does not work: "Unable to get image data from canvas because the canvas has been tainted by cross-origin data." "Uncaught Error: SECURITY_ERR: DOM Exception 18". The only methods I've seen for trying to bypass this problem also seem to generate similar errors, so I'm not sure if what I'm trying to do is outside the limitations of javascript and browser restrictions. – S.C. Mar 18 '12 at 21:58
  • I did some more research and it appears that it may not be possible due to browser restrictions, what browser are you testing this on? – Bigandrewgold Mar 19 '12 at 00:02
  • I've tested this on chrome and firefox. The only reliable way I can see of getting around this without a proxy server is to disable the restrictions on browser startup (i.e. chrome --disable-web-security or something similar for firefox), which will obviously not do for a plugin. Thanks for looking into this. I guess it just might not be feasible. – S.C. Mar 19 '12 at 00:25