#!/usr/local/bin/perl
require 5.001;
use GD;
$imageFile = "/CHANGE/THIS/FILE/name.gif";
$x = -1;
$y = -1;
if ($ENV{"PATH_INFO"} eq "/image.gif") {
# This is a request for an image
open(IN, $imageFile);
$im = newFromGif GD::Image(IN);
close(IN);
$image = 1;
}
$_ = $ENV{"QUERY_STRING"};
if (/(\d+),(\d+)/) {
# This is a request for a magnified portion
# of the image, or the page it will appear in
&Magnify($1, $2, $im, $image);
exit 0;
}
if ($image) {
# Top view: no magnification
print "Content-type: image/gif\n\n";
print $im->gif;
} else {
# Top page, with an tag pointing to
# an unmagnified GIF image
print "Content-type: text/html\n\n";
print "\n";
print "
\n";
print "\n";
print "
\n";
print "\n";
print "\n";
print "\n";
}
exit 0;
sub Magnify
{
local($x, $y, $im, $image) = @_;
if ($image) {
# Generate a 4x magnified image
$mag = new GD::Image(200, 200);
# Copies and stretches the desired portion of the image
$mag->copyResized($im,
0, 0,
$x - 25, $y - 25,
200, 200,
50, 50);
print "Content-type: image/gif\n\n";
print $mag->gif;
} else {
# A page with an tag pointing to
# the magnified GIF and a link to return
# to the normal top-down view
print "Content-type: text/html\n\n";
print "\n";
print "
\n";
print "\n";
print "\n";
}
}