Image sizes and PHP

If you have the GD extension available, you can do a few useful things. One of the simple things is getting an image size is a simple matter. You can either fetch the height and width in seperate variables – or even fetch the height and width in a string pre-formatted for use in an image tag.

Here’s the example in source:

$load\_ext = get\_loaded\_extensions();

if (!in\_array(gd, $load\_ext)) {
    echo "GD is NOT available";

$nikonFile   = './aarhus\_demo\_photo.jpg';
list($width, $height, $type, $img\_txt)  = getimagesize($nikonFile);

echo "The image is ".$width . " by ".$height."\\n";
echo "![]($nikonFile)\\n";

And here’s how it looks (source).