PDA

View Full Version : find image height and width


tylerjca
04-03-2006, 09:09 PM
Hi,

I'm trying to set something up so that when someone uses a display picture that is already uploaded to the server, it resizes the image to either 100px wide OR 100px high, depending on whether the image is wider than it is high, or higher than it is wide...in other words:

<?php
//somehow get height and width before the following..

if($image_height>$image_width)
{
$sizes = "height=\"100\"";
}
else
{
$sizes = "width=\"100\"";
}
?>
<img src="/displays/my_file/image01.jpg" <?=$sizes;?> alt="My Display Pic">


Is this possible? or am I going to have to use Javascript for this?

Brandoe85
04-03-2006, 09:20 PM
Not sure I follow, but does this help?
http://us3.php.net/getimagesize

kewlceo
04-03-2006, 09:37 PM
Is this possible? or am I going to have to use Javascript for this?
Try this:
// find out size of image
$img = @imagecreatefromgif("http://www.kewlceo.com/kewlceo.gif");

if ($img) $imgX = imagesx($img);
if ($img) $imgY = imagesy($img);

echo "Image size = " . $imgX . " x " . $imgY;

kewlceo
04-03-2006, 09:43 PM
Not sure I follow, but does this help?
http://us3.php.net/getimagesize
Your method is even better. :thumbsup:

$size = getimagesize("http://www.kewlceo.com/kewlceo.gif");
echo $size[3]; // formatted string with size w x h

Sample output
width="399" height="409"

Bill Posters
04-03-2006, 10:52 PM
Your method is even better. :thumbsup:

$size = getimagesize("http://www.kewlceo.com/kewlceo.gif");
echo $size[3]; // formatted string with size w x h

Thanks for that.
I didn't know there was a way to echo out both dimensions (correctly formatted) with a single echo. I'd previously been echoing out each attribute individually from the getimagesize array.

I'll be using $arrayname[3] in future.

Ta. ;)

tylerjca
04-04-2006, 11:20 PM
wow! thanks! that just what i needed!