在PHP中检索图像方向

在PHP中检索图像方向

问题描述:

如何在PHP中获取图像(JPEG或PNG)的图像方向(横向或纵向)?

How can I get the image orientation (landscape or portrait) of an image (JPEG or PNG) in PHP?

我创建了一个用户可以上传图片的php网站。在我将它们缩小到较小尺寸之前,我想知道图像是如何定向的,以便正确缩放它。

I created a php site where users can upload pictures. Before I scale them down to a smaller size, I want to know how the image is orientated in order to scale it properly.

感谢您的回答!

我一直这样做:

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