Retrieve image orientation in PHP

list($width, $height) = getimagesize("path/to/your/image.jpg");

if( $width > $height)
    $orientation = "landscape";
else
    $orientation = "portrait";

I suppose you could check if the Image width is longer than the length for Landscape and for Portrait if the Length is longer than width.

You can do that with a simple IF / ELSE statement.

You could also use the function: Imagick::getImageOrientation

http://php.net/manual/en/imagick.getimageorientation.php


I've always done this:

list($width, $height) = getimagesize('image.jpg');
if ($width > $height) {
    // Landscape
} else {
    // Portrait or Square
}

I am using this shorthand. Sharing just in case someone needs a one-line solution.

$orientation = ( $width != $height ? ( $width > $height ? 'landscape' : 'portrait' ) : 'square' );

First it checks if image is not 1:1 (square). If it is not it determines the orientation (landscape / portrait).

I hope someone finds this helpful.