#!/usr/bin/perl # to use cat blogosphere.xml | ./create_dymaxion_map.pl use Imager; use Imager::Fill; use Geo::Dymaxion; # available from CPAN, requires Inline.pm use strict; use warnings; my $base_image_file = "dymaxion.jpg"; my $output_image_file = "dymaxion_map.jpg"; my @dot_color = (255, 0, 0); my $dot_size = 2; $|++; my $map = Imager->new; $map->open( file => $base_image_file ); open( OUT, ">$output_image_file" ) || die "cannot open $output_image_file\n"; my $type = $map->type; #print $cgi->header("image/jpeg"); my $dymax = Geo::Dymaxion->new( $map->getwidth, $map->getheight ); while (<>) { if ($_=~/latitude="([-\.0-9]+)" longitude="([-\.0-9]+)"/) { my $lat = $1; my $long = $2; my ($x, $y) = $dymax->plot( $lat, $long ); warn "plotting ($lat, $long) to ($x, $y)\n"; my $dot = Imager::Color->new( @dot_color ); my $fill = Imager::Fill->new( solid => $dot ); $map->circle( fill => $fill, r => $dot_size, x => $x, y => $y ); } } $map->write( type => "jpeg", fd => fileno(OUT) ) or die $map->errstr;