7 my $css_file   = 'generated.css';
 
   8 my $image_file = 'generated.png';
 
   9 my $class_for_map = 'icon';
 
  11 my $convert_bin  = 'convert';
 
  12 my $identify_bin = 'identify';
 
  15   'css-out=s'    => \$css_file,
 
  16   'image-out=s'  => \$image_file,
 
  17   'icon-class=s' => \$class_for_map,
 
  25 for my $filename (sort @files) {
 
  26    my $image = `$identify_bin $filename`;
 
  27    if (!defined $image) {
 
  28      warn "warning: could not identify image '$filename'. skpping...";
 
  31   $image =~ /^(?<filename>\S+) \s (?<type>\S+) \s (?<width>\d+) x (?<height>\d+)/x;
 
  33     filename => $filename,
 
  41 # for simplification thi will check if all the  images have the same dimensions
 
  43 my $first_height = $images[0]->{height};
 
  44 my $first_width  = $images[0]->{width};
 
  48 for my $img (@images) {
 
  49   die 'heights are not equal' if $first_height != $img->{height};
 
  50   die 'widths are not equal'  if $first_width  != $img->{width};
 
  54 # we'll be lazy and just put them all together left-to-right
 
  55 my $new_height = $first_height;
 
  56 my $new_width  = $first_width * @images;
 
  58 # now copy them all together, and keep a referende to;
 
  60 my $convert_string = "$convert_bin ";
 
  64   $_->{h_offset} = $h_offset;
 
  66   $convert_string .= ' +append ' . $_->{filename};
 
  68   $h_offset += $_->{width};
 
  71 $convert_string .= " -background none +append $image_file";
 
  73 # now write that png...
 
  74 system($convert_string);
 
  78   open my $file, ">", $css_file or die "can't write too $css_file";
 
  79   print $file ".$class_for_map { background: url(../$image_file) ${first_width}px 0px no-repeat; padding: 0; width: ${first_width}px; height: ${first_height}px; }\n";
 
  82     my $name = fileparse($_->{filename}, ".png");
 
  84     # the full grammar for valid css class names is completely bonkers (to put it mildly).
 
  85     # so instead of trying to punch filenames into those class names, we'll
 
  86     # just reduce them to a nice minimal set of lower case /[a-z0-9_-]*/
 
  88     $name =~ s/[^a-z0-9_-]/-/g;
 
  89     print $file ".$class_for_map.$name { background-position: -$_->{h_offset}px 0px; }\n";
 
 101 image_maps - generates image maps for css sprites from images in a directory
 
 105   scripts/image_maps.pl \
 
 106     --out-css=css/icons_16.css \
 
 107     --out-image= image/maps/icons_16.png \
 
 120 Sven Schoeling E<lt>s.schoeling@linet-services.deE<gt>