#!/usr/local/bin/perl use CGI qw/:standard/; use Image::Magick; use URI::Escape; my $color; my $hex_color = '#ffffff'; my $esc_color; my $status; sub hex_color { my ($number, $hex); (shift @_) =~ /^(\d+),(\d+),(\d+)/; foreach $number ($1, $2, $3) { $hex .= sprintf("%02X", 0xff & $number); } return '#' . $hex; } if (param()) { if (defined(param('hex_text'))) { $hex_color = param('hex_value'); $hex_color = '#' . $hex_color if ($hex_color !~ /^\#/); } else { my ($x, $y) = (param('color.x'), param('color.y')); my $image = Image::Magick->new(); $status = $image->read("../htdocs/background.gif"); print STDERR "$status\n" if ($status); $color = $image->Get("pixel[$x, $y]"); $hex_color = hex_color($color); } } $esc_color = uri_escape($hex_color); my $instructions = <<"END_TEXT";

Click the color map or enter a specific hex color in the text box.

END_TEXT print header, start_html({-bgcolor => substr($hex_color, 1)}, 'Background Color Tester'), h1({-align => 'center'}, "Background Color Tester"), h2({-align => 'center'}, "Hex Color Value Is: $hex_color"), h3({-align => 'center'}, $instructions), start_form(), table({-align => 'center'}, Tr({-align => 'center'}, td({-align => 'center'}, image_button(-name => 'color', -src => '/background.gif', -width => 256, -height => 171, -align => 'MIDDLE', ), ), ), ), table({-align => 'center'}, Tr({-align => 'center'}, td({-align => 'center'}, textfield(-name => 'hex_value', -size => 7, ), ), td({-align => 'center'}, submit (-value => 'Hex Value', -name => 'hex_text', ), ), ), ), end_form(), end_html();