Listing 4 Cropping using the frame defined by the coordinates returned by getZoomedInCoords() 

  use Fcntl ':flock';
  use FileHandle;

  # Load the detailed aerial photograph.
  #
  use constant IMAGE_FILE => 'detailed.gd2';

  my $fh = new FileHandle( IMAGE_FILE );
  unless ($fh) { die "Cannot open image file ", IMAGE_FILE; }

  # Lock the detailed image file for safe sharing
  #
  flock( $fh, LOCK_SH );

  $ImgRaw = GD::Image->newFromGd2( $fh );

  flock( $fh, LOCK_UN );
  close( $fh );

  # Create a new image. This will form the basis of our detailed
  # cropped map
  #
  my $ImgCrop = GD::Image->new( CROP_WIDTH, CROP_HEIGHT );

  # Get top-left coordinates of the bounding box 
  #
  my ($x_left, $y_top) = getZoomedInCoords( getImageMapCoords() );

  # Copy the contents of the bounding box to the new image.
  # $ImgCrop now contains the cropped aerial map.
  #
  $ImgCrop->copy( $ImgRaw, 0, 0, $x_left, $y_top, CROP_WIDTH, CROP_HEIGHT );


