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:

1
2
3
4
5
6
7
8
9
10
11
12
$load_ext = get_loaded_extensions();
 
if (!in_array(gd, $load_ext)) {
echo "GD is NOT available";
die();
}
 
$nikonFile   = './aarhus_demo_photo.jpg';
list($width, $height, $type, $img_txt)  = getimagesize($nikonFile);
 
echo "The image is ".$width . " by ".$height."\n";
echo "<img $img_txt src='$nikonFile'/>\n";

And here’s how it looks (source).