HTML, PHP, Website Design

PHP – Finding the Width or Height of an Image

Leave a Reply

Knowing the width, height, Image type or attributes of an image can be extremely useful.

I’ve used this once to make a line of images all line up on the bottom. I found out the height of the image and then added a margin to the top of the image to make the bottom of the image always be 300 px from the to. So if the height of the image was 140, I would make the margin on top of the image = 300-140.

Here’s the code to find the height or width of an Image:

<?php

list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

echo “Image width ” .$width;
echo ”
“;
echo “Image height ” .$height;
echo ”
“;
echo “Image type ” .$type;
echo ”
“;
echo “Attribute ” .$attr;

?>

Enjoy,
Ashton Sanders

Leave a Reply

Your email address will not be published. Required fields are marked *