#!/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 "CGI Magnifying Glass\n"; print "\n"; print "\n"; print "

CGI Magnifying Glass

\n"; print "Click anywhere in the image for a\n"; print "magnified view.\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 "Magnified View\n"; print "\n"; print "\n"; print "

Magnified View

\n"; print "\n"; print "Up to the complete image\n"; # A trick to remember: we generate a src attribute # which will appear to the program just like the original # imagemap click did, but with "/image.gif" in # the PATH_INFO variable. This will invoke the # other branch of this function to generate the image. print "

\n"; print "\n"; print "\n"; } }