#! /usr/bin/perl -w
use CGI qw(:standard :html area);
use GD;
# File met lijst van hotspots
# formaat: x_centrum, y_centrum, breedte, hoogte, kleur, tekst
#
# kleur opgeven in HTML-formaat (#RRGGBB). Wit en zwart niet gebruiken:
# wit wordt transparant en zwart wordt gebruikt voor de teksten.
my $color = '#(\w\w)(\w\w)(\w\w)';
# Afmetingen van uiteindelijk gif plaatje
my @size = (300, 300);
my $font = GD::Font->Large;
my @charsize = ($font->width, $font->height);
open FILE, $ARGV[0] or die "Can't open file $ARGV[0] : $!";
@list = ;
close FILE;
@list = map [split /,/, $_ ], @list;
# Herschaal coordinaten en afmetingen.
$xmin = $xmax = $list[0][0];
$ymin = $ymax = $list[0][1];
for (@list) {
$_->[2] = -$_->[2] if $_->[2] < 0;
$_->[3] = -$_->[3] if $_->[3] < 0;
$xmin = $_->[0] - $_->[2] / 2.0 if $xmin > $_->[0] - $_->[2] / 2.0;
$ymin = $_->[1] - $_->[3] / 2.0 if $ymin > $_->[1] - $_->[3] / 2.0;
$xmax = $_->[0] + $_->[2] / 2.0 if $xmax < $_->[0] + $_->[2] / 2.0;
$ymax = $_->[1] + $_->[3] / 2.0 if $ymax < $_->[1] + $_->[3] / 2.0;
}
my $xshift = -$xmin;
my $xscale = $size[0] / ($xmax - $xmin);
my $yshift = -$ymin;
my $yscale = $size[1] / ($ymax - $ymin);
for (@list) {
$_->[0] = ($_->[0] + $xshift) * $xscale;
$_->[1] = ($_->[1] + $yshift) * $yscale;
$_->[2] *= $xscale;
$_->[3] *= $yscale;
}
$im = new GD::Image (@size);
my $white = $im->colorAllocate(255, 255, 255);
my $black = $im->colorAllocate(0, 0, 0);
my $border = $im->colorAllocate(1, 0, 0);
$im->transparent($white);
# Teken de ellipsen en genereer HTML code voor imagemap
#print start_html(); # Volledig html bestand
print " \n";
# Construeer gif plaatje en genereer de benodigde HTML code.
my $giffile = $ARGV[1];
if ($giffile !~ /\./) { $giffile .= ".gif"; };
my $png_data = $im->png;
open GIF, "| convert - $giffile" || die "Can't open pipe to command 'convert' : $!";
print GIF $png_data;
close GIF;
print center(img({src => $giffile, usemap => "#proteinmap", ismap => '', border=>0})), "\n";
#print end_html(); # volledig html bestand
exit(0);