▼  Site Navigation Main Articles Search  ▼  Anime + Manga Anime Reviews Anime Characters Gallery Screenshots Manga Reviews  ▼  Misc News Links to Webcomics Bible Quotes About Older Musings
site version 7.3
PHP –– detect image properties
written by: admin

Date Written: 7/22/08 Last Updated: 3/19/10

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);
echo "$imageinfo[1]<br>";print_r($imageinfo);

This can be used to create a script that will automatically limit the size of an image on your website.

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

[0] = image height
[1] = image width
[2] = ?
[3] = 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.  

Getimagesize() does indeed get the image size, but also gets other facts about the image as well as stated above.

TAGS: images, php

Go to phpbb thread.
copyright 2005–2021