Net-Flickr-Geo
view release on metacpan or search on metacpan
lib/Net/Flickr/Geo/ModestMaps.pm view on Meta::CPAN
return $acc + 1;
}
}
sub fetch_modestmap_image {
my $self = shift;
my $args = shift;
my $out = shift;
$out ||= $self->mk_tempfile(".jpg");
my $timeout = $self->divine_option("modestmaps.timeout", (5 * 60));
my $remote = $self->divine_option("modestmaps.server");
my $mm = Net::ModestMaps->new();
$mm->host($remote);
$mm->timeout($timeout);
$mm->ensure_max_header_lines($args->{'marker'});
my $data = $mm->draw($args, $out);
if (my $err = $data->{'error'}){
$self->log()->info("modestmaps error : $err->{'code'}, $err->{'message'}");
return undef;
}
$self->log()->info("received modest map image and stored in $out");
return $data;
}
sub modify_map {
my $self = shift;
my $ph = shift;
my $map_data = shift;
my $thumb_data = shift;
my @pw_details = split(",", $map_data->{'marker-thumbnail'});
my $pw_x = $pw_details[2];
my $pw_y = $pw_details[3];
my $pw_w = $pw_details[4];
my $pw_h = $pw_details[5];
my @images = ([$thumb_data->{path}, $pw_x, $pw_y, $pw_w, $pw_h]);
return $self->place_marker_images($map_data->{'path'}, \@images);
}
sub place_marker_images {
my $self = shift;
my $map_img = shift;
my $markers = shift;
# use GD instead of Imager because the latter has
# a habit of rendeing the actual thumbnails all wrong...
# ensure the truecolor luv to prevent nasty dithering
my $truecolor = 1;
my $im = GD::Image->newFromPng($map_img, $truecolor);
foreach my $data (@$markers){
my ($mrk_img, $x, $y, $w, $h) = @$data;
my $ph = GD::Image->newFromJpeg($mrk_img, $truecolor);
eval {
$im->copy($ph, $x, $y, 0, 0, $w, $h);
};
if ($@){
$self->log()->error("picture made GD cry, skipping. $@");
}
unlink($mrk_img);
}
unlink($map_img);
return $self->write_jpeg($im);
}
sub place_map_images {
my $self = shift;
my $map_data = shift;
my $urls = shift;
my @images = ();
foreach my $prop (%$map_data){
if ($prop =~ /^marker-(.*)$/){
my $id = $1;
my $ph_url = $urls->{$id};
my $ph_img = $self->mk_tempfile(".jpg");
$self->log()->info("fetch $ph_url");
if (! $self->simple_get($ph_url, $ph_img)){
$self->log()->error("failed to retrieve $ph_url, $!");
next;
}
my @pw_details = split(",", $map_data->{$prop});
my $pw_x = $pw_details[2];
my $pw_y = $pw_details[3];
my $pw_w = $pw_details[4];
my $pw_h = $pw_details[5];
push @images, [$ph_img, $pw_x, $pw_y, $pw_w, $pw_h];
}
}
return $self->place_marker_images($map_data->{'path'}, \@images);
}
#
# search
#
( run in 1.386 second using v1.01-cache-2.11-cpan-39bf76dae61 )