Drupal 7 snippet to determine if an image is mostly dark or mostly light

Valid XHTML 1.0 Transitional