<html>
<head><title>Image Info</title></head>
<body bgcolor="#ffffff">
<table>
% for (@order) {
%   next unless defined $data{$_};
 <tr>
  <td align="right"><b><% $_ |h %>:</b></td>
  <td align="left"><% $data{$_} |h %></td>
 </tr>
% }
</table>
<div align="center">
<br>
<form action=#>
<input type=submit value="Done" onclick='parent.close()'>
</form>
</div>
</body>
</html>
<%init>
    my ($path, %info, @order, %data, $type, $size);

    $path = "$ENV{DOCUMENT_ROOT}/$_[0]";
    %info = %{ (image_info($path))[0] };
    $type = uc((split(/\//, $info{file_media_type}))[1]);

    $size = -s $path;
    for (qw(bytes KB MB GB)) {
	if ($size < 1024) {
	    $size = sprintf('%.1f %s', $size, $_);
	    last;
	}
	$size /= 1024;
    }
    $size =~ s/\.0//;

    %data = (
	Name		=> basename($path),
	Dimensions	=> "$info{width}x$info{height}",
	Type		=> $type,
	'File Size'	=> $size,
    );

    if ($type eq 'GIF') {
	$data{'GIF Version'} = $info{GIF_Version};
    } elsif ($type eq 'PNG') {
	$data{Filter} = $info{PNG_Filter};
	$data{Gamma} = $info{Gamma};
	$data{'Color Type'} = $info{color_type};
	$data{Software} = $info{Software};
    } elsif ($type eq 'JPEG') {
	$data{'Color Type'} = $info{color_type};
	$data{'JPEG Type'} = $info{JPEG_Type};
	if (exists $info{ExifImageWidth}) {
	    $data{'Focal Length'} = sprintf('%.2fmm', 
		$info{FocalLength}[0] / $info{FocalLength}[1]);
	    $data{'Exposure Time'} = 
		"$info{ExposureTime}[0]/$info{ExposureTime}[1] sec";
	    $data{Flash} = $info{Flash};
	    $data{ISO} = $info{ISOSpeedRatings};
	    $data{'F-Number'} = sprintf('f/%.1f', 
		$info{FNumber}[0] / $info{FNumber}[1]);
	    $data{'Camera Make'} = $info{Make};
	    $data{'Camera Model'} = $info{Model};
	    if ($info{DateTime} =~ 
			    /^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/) {
		$data{Created} = strftime('%a, %B %e at %l:%M:%S%p',
		   $6, $5, $4, $3, $2 - 1, $1 - 1900); 
	    }
	}
    } else {
	die "unknown type; '$type'";
    }

    @order = (
	'Name',
	'Dimensions',
	'Type',
	'File Size',
	'GIF Version',
	'Filter',
	'Gamma',
	'Color Type',
	'Software',
	'JPEG Type',
	'Focal Length',
	'Exposure Time',
	'Flash',
	'ISO',
	'F-Number',
	'Camera Make',
	'Camera Model',
	'Created',
    );
</%init>
