Bookmarklet request
Anyone know if it would be possible to create a bookmarklet that emulates an EyeDropper style application: as you move it around the page it shows you the hex colour code for the pixel directly under the mouse pointer? I’m pretty sure it can’t be done but I’d love to be proved wrong.
Well, originally I thought it could be done if:
Which would give you a nasty brute force parse-the-dom-tree-on-mouse-move type solution. However what color do you want? Borders are a pain - you could calculate if you were over a border I suppose. Then I thought "What about text?". If you want foreground colours you're out of luck - how are you going to determine your cursor is over some text? Don't even get me started on the complexities of background images. Whats the problem with using Eye Dropper? Is it PC only?
sam newman - 19th April 2004 00:41 - #
Simon Willison - 19th April 2004 00:50 - #
http://www.iconfactory.com/xs_home.asp
Justin - 19th April 2004 01:16 - #
It's not quite what you're looking for, but Chris Pederick's Web Developer Extension for Mozilla and Firefox has a "View Style Information command which displays the complete CSS inheritance tree of an object, although it only works on certain compilations of the browser. From there it becomes easier to work out what colour is being applied, and you could always take the code and tweak it to work out foreground and background colour (and take things in like non-CSS styles) and display them at your whim.
Dunno if there's something similar for Safari though, but it's a start.
Moof - 19th April 2004 01:19 - #
Dave Giffin - 19th April 2004 01:29 - #
Chris Vincent - 19th April 2004 03:17 - #
I'm not really sure how it could be done via bookmarklets either. For those looking for a PC-side solution, I find ColorPad (working mirrors in the comments section) to be a pretty good software color picker.
It's a small program that sits in your taskbar tray. While the interface is compact, it still manages to provide a lot of features and a good amount of feedback. Most importantly, it doesn't feel like it gets in the way.
starvingartist - 19th April 2004 04:34 - #
sil - 19th April 2004 06:31 - #
Hang on, here's a thought: What if you were to load the image under the cursor using XmlHttpRequest (or the IE equivalent ActiveX thingy) and pull the binary image in to a Javascript array. Then write a Javascript JPEG/GIF decoder which could be used to figure out the colour of the specific co-ordinate of the image.
Of course, the whole thing would have to run fast enough to keep up with the changes in the onmousemove() events... so maybe not.
Simon Willison - 19th April 2004 06:52 - #
Client-side may not be the most appropriate. If you're talking about sampling from an image, you could use server-side image maps (remember those?).
However, you need some kind of indication about what colour is under the cursor. Browsers give you all the tools you need for that. Obtain the (x,y) position over the image, and have a second copy of the image nearby at, say, 800% enlargement; crop the edges and reposition in sync with the cursor. You won't programmatically get the colour but there will be a visual representation.
I would love to see a combination of both these approaches, if you decide to try it out!
Owen - 19th April 2004 09:34 - #
JavaScript JPEG decoder? Not a snowball's chance in hell!
Or rather it *is* possible, but it would be such a HUGE amount of code and it would run SO slowly that it would be completely unusable.
BMPs would be fine, but PNGs would be as nightmarish as JPEGs, if not moreso (think alpha blending)...!
;)
Marcus Tucker - 19th April 2004 09:45 - #
Rich - 19th April 2004 12:55 - #
Simon Willison - 19th April 2004 13:31 - #
Get this - the feature was available way back in Mosaic 3!
There's an interesting thread about this here:
http://www.webmasterworld.com/forum21/7708.htm
Chris Hester - 19th April 2004 15:49 - #
Blakems - 19th April 2004 16:10 - #
Will Rickards - 19th April 2004 16:44 - #
http://slayeroffice.com/test/cpick/
Steve - 19th April 2004 17:50 - #
Rich - 19th April 2004 21:08 - #
Peter Mantik - 6th June 2004 12:21 - #
Dan - 12th June 2004 11:24 - #
windflash - 14th June 2004 14:34 - #
blackjack - 15th June 2004 16:27 - #
raydancer - 21st April 2005 18:10 - #
gfdg - 10th September 2005 10:04 - #
Aparna - 9th March 2006 09:06 - #
Glenn Franxman - 18th May 2006 07:38 - #