If you know the filename this will pull up some info about the file.
PHP Code:
<pre><?php
$image = $_SERVER['DOCUMENT_ROOT'].'/images/Lain.JPG';
$imageinfo = GetimageSize($image);
print_r($imageinfo);
?></pre>
returns
PHP Code:
Array
(
[0] => 1024
[1] => 768
[2] => 2
[3] => width="1024" height="768"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
PHP Code:
[0] = width
[1] = height
[2] = indicates the type of image (dunno what that means)
[3] = width and height together
[bits] = number of bits per color
[channels] = channels per pixel (don't know what this means either)
[mime] = jpg, gif, etc.
If you want to list the images in a given folder use this:
PHP Code:
<?php
$imgdir = 'images'; // the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}
$totimg = count($a_img); // total image number
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.'/'.$a_img[$x]);
// do whatever
$halfwidth = ceil($size[0]/2);
$halfheight = ceil($size[1]/2);
echo 'name: '.$a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
}
?>
techietim, could you give an example of how fileinfo works? I could not get their examples to work.
Bookmarks