Just a little picture

May 19, 2009

PHP getimagesize()

Calling getimagesize() returns an array:

Array
(
    [0] => 300
    [1] => 200
    [2] => 2
    [3] => width="300" height="200"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

The value in index 3 is a text string that expresses the image's width and height.

So:

<img src="image.jpg" alt="Descriptive text" <?php $dimensions = getimagesize("image.jpg"); echo "$dimensions[3]"; ?> />

Posted by Charles on May 19, 2009 04:57 PM






Content licensed under
Creative Commons License