9 June 2011 - 13:33Restartless Dominant Color

I’ve packaged Margaret’s getDominantColor code into a restartless add-on and put the source up on GitHub for people to try out and tweak the logic.

After installing the add-on, hold shift while pointing at an image to have it report the color and show it behind the image. One slight difference from Margaret’s code is that color and transparency values are rounded down to a multiple of 16.

Pointing at an image in about:addons

Download the add-on and check out the code!

10 Comments | Tags: Add-on, Development, Mozilla

Comments:

  1. Luke Wagner says: 09 Jun 2011 - 22:22

    Cool! Its impressive how “right” it looks for the ones I was trying out.

  2. Interesting but why the rounding? You can manually round the exact color value if you want but the reverse is not possible.

  3. Nice little extension, while looking through the code (trying and failing to implement it in PHP), I noticed the blue and green channels are mixed in the getDominantColor function (it all works out in the end, but it’s a tad confusing)

  4. @Dis what do you mean the reverse isn’t possible? Are you concerned that the rounded color is used instead of the actual color?

  5. @Alex Oh ha thanks. Yeah the red, blue, green values aren’t really used for anything in particular right now, but would have led to bugs if I used the incorrect variables converting to something like HSV.

  6. Is this a “plain” restartless addon (using only “common” Core and Toolkit code, so it would work on SeaMonkey and maybe Thunderbird with a tweaked install.rdf) or does it use the Firefox-only Jetpack SDK?

  7. @Tony It’s a plain bootstrapped add-on, but I haven’t tested on those other apps. It should actually work on Fennec for Desktop as well assuming there’s mousemove events and shift keys. 😉

  8. @Ed: OK, I’ve uploaded a version where the only changes I made was adding a couple of sections in install.rdf: AFAICT it works in the current trunk nightly of SeaMonkey, and it ought to install (at least for testing purposes) on any application built on Toolkit >= 2.0. I haven’t tested it on Thunderbird but it ought to work in current comm-miramar or comm-central builds. You can get it at http://users.skynet.be/antoine.mechelynck/other/dominant_color-2-fx+sm.xpi

    The results are sometimes surprising when used on partly-transparent images displayed on top of each other.
    It does *not* work on some images, as follows:
    – on the SeaMonkey tabs it seems to access the “generic tab icon”, not the favicon actually displayed (it works OK on the favicon in the URL bar)
    – on some buttons in the browser chrome it seems to access the image from which the button was cut out (i.e., it shows several buttons in a kind of array, not just the one pointed at)
    – on the CGI counter on my homepage http://users.skynet.be/antoine.mechelynck/ it accesses the placeholder image which is displayed when that link is on a page at a different HTML address, which is not authorized to display (and increase) the counter

  9. […] yesterday’s initial add-on for a Restartless Dominant Color, I’ve taken some ideas from the Firefox UX team to associate search engines with a color. […]

  10. Not only does it produce good-looking images, but I found it to be a useful tool for quickly seeing the full version of clipped/partially hidden images.


Subscribe without commenting

Add a Comment