#!/usr/arch/bin/perl
# get latest version of gd (1.8.3) cuz it supports jpegs!!!
# >= 1.8 at least
use GD;
use CGI qw(:standard);
$x = param('SarImage.x');
$y = param('SarImage.y');
$picName = param('picName');
$rectSize = 400;
$ext = ".gif";
$file = $picName . $ext;
if (-e $file)
{
open (PIC, $file);
$srcImage = newFromGif GD::Image(PIC);
# try using getBounds to get size dimensions
close PIC;
# y will be less that x (5488 x 4999)
$x = $x * 6;
$y = $y * 5.5;
$div = $rectSize / 2;
$startX = $x - $div;
$startY = $y - $div;
if ($startX < 0) {
$startX = 0;
}
if ($startY < 0) {
$startY = 0;
}
$newImage = new GD::Image($rectSize, $rectSize);
# GD::Image::copy(sourceImage,dstX,dstY,srcX,srcY,width,height)
$newImage->copy($srcImage, 0, 0, $startX, $startY, $rectSize, $rectSize);
print header('image/gif'), $newImage->gif;
}
else
{
print "Content-type: text/html\n\n";
print "Can't find gif file...
\n";
print "test: $picName
\n";
}