I am using a subroutine I found to obtain the dimansions of a gif image. The sub returns a reference to the data but when I attempt to dereference it ie. $$height or $$width I get SCALAR(0xed880) SCALAR(0xed898) instead of the values I'm looking for. I have tried returning the vars $height and $width directly but the data they contain is innacurate when compared to the original image.
Does the expression: return \($width, $height);
require some other syntax to dereference properly?
Should the syntax be: return (\$width, \$height);
to dereference properly?
This is how I am attempting to use the subroutine:
I'm sure I'm missing something obvous but I'm stumped# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 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); }
My thanks to The Monastery
NereDoWell
In reply to dereferencing problem by NereDoWell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |