PSSGCSim
PSSGCSim

Reputation: 1287

Recognize if image is landscape or portrait

How can I recognize if image stored in same folder as PHP script is landscape or portrait ? I need to implement it to this function:

if ($dir = @opendir($folder))
{
    while ($file = readdir($dir))
    {
        if (in_array(strtolower(FileExt($file)), $extensions))
        {
            if (!is_dir($file))
            {
                if (isLandsape($file))
                {
                    $files[] = $file;
                }
            }
        }
    }

    closedir($dir);
}

Upvotes: 1

Views: 3814

Answers (2)

Yohann Tilotti
Yohann Tilotti

Reputation: 165

A function like this :

function isLandsape($file)
{
  list($width, $height) = getimagesize($file);
  return $width > $height;
}

Upvotes: 4

Joshua Terrill
Joshua Terrill

Reputation: 2017

list($width, $height) = getimagesize($file);

if ($width > $height) {
    $orientation = "Landscape"; }
 else {
    $orientation = "Portrait"; }

Upvotes: 3

Related Questions