PDA

View Full Version : Javascript to verify images



joncombe
08 Mar 2011, 05:22 PM
I have a couple of websites that contain photos and here in the UK at least a lot of people now access the internet with mobile broadband. The providers of such services have in many cases taken it upon themselves to automatically apply some sort of image "optimisation" proxy that greatly reduces the quality of images before they are loaded with the result that websites often look a mess with over-compressed and blurry images. I'm actually surprised this is legal since strictly the ISPs are modifying copyrighted data without the copyright holders permission. Some (e.g. T-Mobile) do not even allow the user to turn this off. Usually they also add javascript to put a "Press Ctrl+? to download uncompress images" when you hover over any image to get the original. Legal implications aside it has got me thinking.

I don't like this situation and at least want to put up some sort of banner to say the images have been modified and should be better quality or some such. What I thought of doing was including in all my pages a hidden table containing the filename and an MD5 hash of the image data for all images on the page. Then using Javascript to parse through this and perform an MD5 of the actual downloaded image data to see if it varies. This would allow me to detect the images have been modified between leaving the web server and arriving at the users PC.

However having had a quick play I'm wondering if this is possible? There doesn't seem to be a way to access raw image files in Javascript. I also considered the possibility of some Javascript to perhaps randomly pick an image from the table, and then request the raw file for it via an AJAX request and then compare it again. Is that possible? It has to be client side since the changes to the image data occur after they have left the web server.

Any advice appreciated.