...

View Full Version : working out if an image is portrait or landscape is causing trouble



LJackson
10-14-2012, 04:24 AM
hi all,

i have the following piece of code


$files = listdir($directory);
$counter = 1;
foreach ($files as $f)
{
$size = getimagesize($f);
list($width, $height, $type, $attr) = getimagesize($f);
if($counter == 1 && $width > $height)
{
echo "w = ".$width;
echo "h = ".$height;
$default_file = $f;
$target_file = $f;
$filename = explode("/",$f);
$filename = $filename[3];
echo "file = ".$filename;
echo "TF = ".$target_file;
$kaboom = explode(".", $target_file); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension
echo "FE = ". $fileExt;
$resized_file = $directory."/".$filename;
echo "RF = ". $resized_file;
$wmax = 260;
$hmax = 260;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
#echo $f, "\n";
}
$counter++;
}


which grabs a list of images from a directory, it then finds out the images dimensions and then checks to see if $counter == 1; and that $width > $height. as i only want to return the landscape images

unfortunately the

&& $width > $height
part of the if statement seems to always return false despite some of the images are landscape

it works ok if i remove the above but then i get portrait images too :(

any idea why this would be causing it to fail?
cheers
Luke

LJackson
10-14-2012, 05:27 AM
solved it

in the end i used

$calc = ($width - $height);
if($counter == 1 && $calc > 0)

which worked, any idea why my previous statement failed?

cheers

DrDOS
10-14-2012, 04:59 PM
Did you try ?

&&($width > $height )



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum