#!/usr/local/bin/perl use strict; use warnings; use CGI; use CGI::Carp qw/fatalsToBrowser/; use Imager; use LWP::UserAgent; our $VERSION = sprintf "%d.%02d", q$Revision: 0.1 $ =~ /(\d+)/g; my $q = CGI->new; my $uri = $q->param('u'); $uri =~ s,^(https?:)/+,$1//,o or die 'invalid scheme: ', $q->escapeHTML($uri); my $agent = $0; $agent =~ s,.*/,,o; $agent .= "/$VERSION"; my $ua = LWP::UserAgent->new( timeout => 15, keep_alive => 1, agent => $agent ); my $res = $ua->get($uri); die $res->status_line unless $res->is_success; my $type = $res->header('Content-Type'); die "Unknow MIME type:" unless $type =~ s,^image/,,io; my $img = Imager->new(); my $data = $res->content; my $size = $q->param('s') eq 'l' ? 32 : 16; $img->read( data => $data, type => $type ) or die $img->errstr; my $ico = $q->param('p') ? $img->scale( xpixels => $size, ypixels => $size, type => 'min' ) : $img->scaleX( pixels => $size )->scaleY( pixels => $size ); $ico->write( data => \$data, type => 'ico' ) or die $ico->errstr; print "Content-Type: image/x-icon\n\n$data";