#!/usr/bin/perl use strict; use warnings FATAL => 'all'; use LWP::Simple; use Image::Magick; my %config = ( zoom => 3, # Google Maps zoom level (1 == smallest resolution) x_start => -2387, # Upper-left map tile "x" CGI GET parameter y_start => -1095, # Upper-left map tile "y" CGI GET parameter rows => 108, # Number of rows (i.e. y-axis or height) to fetch cols => 47, # Number of columns (i.e. x-axis or width) to fetch file => 'map.gif', # Filename to save the merged tiles into s_secs => 5, # Number of seconds to sleep in each fetch interval s_every => 18, # Number of tiles to fetch in a given interval get_est => 0.21, # Estimated number of seconds to fetch a tile width => 768, # Desired width for cut image plates height => 1008 # Desired height for cut image plates ); my ($tiles_count, $tiles_total) = (0, $config{rows} * $config{cols}); my $eta = $config{rows} * $config{cols} / $config{s_every} * $config{s_secs} + $config{rows} * $config{cols} * $config{get_est}; my $start_time = time; for (my $y = 0; $y < $config{rows}; $y++) { for (my $x = 0; $x < $config{cols}; $x++) { $tiles_count++; getstore( 'http://mt.google.com/mt?' . 'x=' . ( $config{x_start} + $x ) . '&y=' . ( $config{y_start} + $y ) . '&zoom=' . $config{zoom}, join('_', 'plate', $x, $y) . '.gif' ); sleep $config{s_secs} if (int($tiles_count/$config{s_every}) == $tiles_count/$config{s_every}); } } my $plates = new Image::Magick; for (my $y = 0; $y < $config{rows}; $y++) { for (my $x = 0; $x < $config{cols}; $x++) { $plates->Read('plate_' . $x . '_' . $y . '.gif'); } } my $width = $plates->[0]->Get('columns'); my $height = $plates->[0]->Get('rows'); my $single_map = $plates->Montage( geometry => $width . 'x' . $height . '+0+0', tile => $config{cols} ); $single_map->Write($config{file}); for (my $y = 0; $y < $config{rows}; $y++) { for (my $x = 0; $x < $config{cols}; $x++) { unlink 'plate_' . $x . '_' . $y . '.gif'; } } $single_map->Rotate(degrees => 90); $width = $single_map->[0]->Get('columns'); $height = $single_map->[0]->Get('rows'); my $x_count = int($width / $config{width}); my $y_count = int($height / $config{height}); for (my $x = 0; $x <= $x_count; $x++) { for (my $y = 0; $y <= $y_count; $y++) { my ($w, $h) = ($config{width}, $config{height}); $w = $width - $x_count * $config{width} if ($x == $x_count); $h = $height - $y_count * $config{height} if ($y == $y_count); my $geometry = $w . 'x' . $h . '+' . $config{width} * $x . '+' . $config{height} * $y; my $plate = $single_map->Clone; $plate->Crop(geometry => $geometry); $plate->Montage(geometry => $w . 'x' . $h . '+0+0')->Write( 'plate_' . $x . '_' . $y . '.gif' ); } }