PHP – Finding the Width or Height of an Image

Published by Leave your thoughts

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:


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;


Ashton Sanders

Tags: , , , , , ,

Categorised in: HTML, PHP, Website Design

This post was written by Ashton