在PHP中检索图像方向 [英] Retrieve image orientation in PHP

查看:118
本文介绍了在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
}

这篇关于在PHP中检索图像方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆