• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 818
  • Last Modified:

Zoom-in, Zoom-out, and Pan script !

I need to zomm-in out and pan images from a web page. I don't want to use Java but CGI.
Does anybody knows how or where to find such scripts.

1 Solution
would be fairly easy to write if you use ImageMagick since it will allow you to select parts of an image and create a new image.  So a zoom would just select a part of it.  The standard image would take the whole image but have ImageMagick re-size it down to the size you want, etc.

No1Author Commented:
Can you invoke it from a web page. The zoom-in and out should be done on the fly. If yes where to find ImageMagick please.
There are two options using modules. Which one you'll use will depend on what will work on your platform, and what type of images you are displaying. Both modules are available from CPAN (http://www.cpan.org/).

Option 1 is GD, from Lincoln D. Stein (http://www.cpan.org/authors/id/LDS/GD-1.19.tar.gz). It is based on Thomas Boutell's gd library, which is included in the package. It can only manipulate GIF images. Usage is simple:

use GD;

# read gif image
open SRC, "path/to/image.gif";
my ($oSrcImg) = GD::Image::newFromGif(SRC);
close SRC;

# create target image, same size as src
my ($iW, iH) = $oSrcImg->getBounds();
my ($oTargetImg) = new GD::Image($iW, $iH);

# resize (zoom in on top left quarter);
$oTargetImg->copyResized($oSrcImage, 0, 0, 0, 0, $iW, $IH, int($iW / 2), int($iH / 2));

# return data to browser
print "Content-Type: image/gif\n\n";
binmode STDOUT; # May be necessary on some systems.
print $oTargetImg->gif();

Option 2 is Image::Magick (http://www.cpan.org/authors/id/JCRISTY/PerlMagick-4.26.tar.gz) by John Cristy. It requires the ImageMagick library. The install files coming with the perl package tell you where to get it, and how to install it. It can manipulate a wide range of image types, in many different ways. It is more versatile than GD, but you may have difficulties getting it compiled.

Example code:
use Image::Magick

my ($sRet); # Return value from methods. Use this to
            # detect errors.
my ($oImg) = new Image::Magick();
$sRet = $oImg->Read('path/to/image.jpg');

# get width and height
my ($iW) = $oImg->Get('width');
my ($iH) = $oImg->Get('height');

# Zoom to twice the size
$oImg->Zoom(width=>(2 * $iW), height=>(2 * $iH));
# And Crop to top left corner
$oImg->Crop(x=>0, y=>0, width=>$iW, height=>$iH);

# return to browser
print "Content-Type: image/jpg\n\n";
binmode STDOUT; # May be necessary on some systems.

You can find the full documentation of the Image::Magick module at http://www.wizards.dupont.com/cristy/www/perl.html

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now