Hey All,
Assuming a folder with but two image files, I would like to compare the sizes, and pass the name of the smaller to db.table.Thumbnails, and the larger to db.table.Photo. I have code working for the file names and sizes, but not sure how to go about comparing sizes and passing the file names each to a variable. :bemused:
<?php
$imgdir = 'images/bike_shop/temp'; // directory where images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes allowed
$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]);
$halfwidth = ceil($size[0]/2);
$halfheight = ceil($size[1]/2);
echo $a_img[$x].' width: '.$size[0].' height: '.$size[1].'<br />';
}
/*************************
// here's where I need help --
// don't really want to echo, just pass the names to appropiate db_fields 'Thumbnail' & 'Photo'
$thumbnail = name.smaller.image;
$photo = name.larger.image;
*****************************/
?>
Any help would be appeciated. 😃