Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation working out if an image is portrait or landscape is causing trouble

    hi all,

    i have the following piece of code

    PHP Code:
                                    $files listdir($directory);
                                    
    $counter 1;
                                    foreach (
    $files as $f
                                    {
                                        
    $size getimagesize($f);
                                        list(
    $width$height$type$attr) = getimagesize($f);
                                        if(
    $counter == && $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
    PHP Code:
    && $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

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    solved it

    in the end i used
    PHP Code:
    $calc = ($width $height);
    if(
    $counter == && $calc 0
    which worked, any idea why my previous statement failed?

    cheers

  • #3
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,181
    Thanks
    15
    Thanked 253 Times in 253 Posts
    Did you try ?

    &&($width > $height )


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •