# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Display the uploaded file. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # $MyFileName = "$ClassPath/classimg/$UpLoadedImg"; if (-e $MyFileName){ ($width, $height) = gifdim($MyFileName); if ($$height > 150){ # If the image is too tall for the display area # reduce the height to fit and recalculate the width $NewHeight = 150; $NewWidth = $$width - ($$height - 150); } elsif ($width > 150){ # If the image is too wide for the display area # reduce the width to fit and recalcualte the height $NewWidth = 150; $NewHeight = $$height - ($$width - 150); } # The image will fit in the display area so leave it alone else { $NewHeight = $$height; $NewWidth = $$width; } } # more code ... sub gifdim ($) { # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Get the dimensions of a gif # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # my $filename = $_[0]; open(GIF, $filename) || return (undef, undef); my $buf = ''; my $n = read GIF, $buf, 10; close GIF; return (undef, undef) if $n < 10; my ($head, $width, $height) = unpack("A6vv", $buf); ($head, $width, $height) = unpack("A6vv", $buf); return (undef, undef) unless $head =~ /^GIF8[79]a/; return \($width, $height); # return ($width, $height); }