PHP –– detect image properties
written by: admin
7/22/08 Last Updated:
This handy bit of code will display some facts about an image on your website.
$image = $_SERVER['DOCUMENT_ROOT'].'/images/Council.jpg';
$imageinfo = GetimageSize($image);
This can be used to create a script that will automatically limit the size of an image on your website.
Array (  => 400  => 300  => 3  => width="400" height="300" [bits] => 8 [mime] => image/png )
 = image height
 = image width
 = ?
 = width and height together in a readable format
[bits] = image color depth.
[mime] = file type
[mime] is handy because if I were to incorrectly rename a file as image.jpg when it is actually image.png [mime] will recognize what the real image type is. Renaming a file does not change its properties. A rose by any other name is still a rose, etc.
Breaking the script apart a little further, $image = $_SERVER['DOCUMENT_ROOT'].'/images/Council.jpg';
will retrieve the location for Council.jpg based on the location of the file relative to the root directory. This means that no matter what directory this script is in the file can be found.
does indeed get the image size, but also gets other facts about the image as well as stated above.TAGS: images
Go to phpbb thread.