#!/usr/bin/perl use strict; use warnings; use POSIX qw(floor); use GD::Image; # use GD::Simple; use Data::Dumper; my %map_data = ( border_left => 5.8, border_right => 17.2, border_bottom => 45.8, border_top => 55.1, ); my %img_data = ( max_x => 800.0, max_y => 1029.0, ); my %coords; sub as_pixel_coords { my $m = shift; my $i = shift; my $t = shift || [ 50.107368, 8.664651 ]; # ffm centralstation my $x_pixel = floor( ( $t->[1] - $m->{'border_left'} ) * ( $i->{'max_x'} / ( $m->{'border_right'} - $m->{'border_left'} ) ) ); my $y_pixel = floor( ( $t->[0] - $m->{'border_top'} ) * ( $i->{'max_y'} / ( $m->{'border_bottom'} - $m->{'border_top'} ) ) ); return $x_pixel, $y_pixel; } sub area_tag { my ( $y, $x, $radius, $url, $user, $uid ) = @_; $url ||= 'http://www.example.net/forum/member.php?u='; $user ||= 'john doe'; $uid ||= '0815'; return qq{ }; } open(my $db, '<', 'opengeodb.txt') or die $!; while (<$db>) { chomp; next if /^#/ or /^\s*$/; my $row = [ split /;/, $_ ]; $coords{$row->[-1]} = [ $row->[-2], $row->[-3] ]; } close $db or warn $!; my $img = GD::Image->new( 'au_ch_de.png' ); @img_data{'max_x', 'max_y'} = ( $img->width(), $img->height() ); my $red = $img->colorAllocate(255,0,0); print q{ Karte }; while() { chomp; next unless /^\w+;\d+;\d+$/; my ($user, $uid, $postcode) = split /;/; $img->filledEllipse( as_pixel_coords( \%map_data, \%img_data, $coords{$postcode} ), 7, 7, $red ); print area_tag( as_pixel_coords(\%map_data, \%img_data, $coords{$postcode}), 7, undef, $user, $uid ); } print q{ }; open(MAP, '>', 'map.png') or die $!; print MAP $img->png; close MAP; __DATA__ tim;201;64287 tom;202;80331 joe;203;20095 bob;204;01067