当看起来没有任何EXIF数据时,Windows文件资源管理器如何知道照片的方向?

问题描述 投票:1回答:1

我用PHP开发了一个网站,显示了我多年来拍摄的数千张照片。到目前为止,我对方向没有任何问题 - 横向和纵​​向图片都能正确显示。

我最近开始编辑一些照片,它改变了一些方向。我现在修改了我的代码以处理EXIF的'Orientation'数据(使用Wes on Stack Overflow创建的'correctImageOrientation'功能 - 非常感谢Wes!)来相应地旋转照片并且效果很好。

但是,我编辑的一些照片现在没有EXIF Orientation数据,因此我无法使用它来旋转照片,但文件浏览器以某种方式知道正确的方向并正确显示照片。因此,我的问题是文件资源管理器从哪里获取照片方向以及如何从PHP访问它?

php orientation photo exif
1个回答
1
投票

无法发表评论,因此将发布为答案。

Exif数据只是特定设备使用的元数据。否则它可以被剥离。你可以探索this workaround from the comment section in php's manual

$orientation = 1;
if (function_exists('exif_read_data')) {
    $exif = exif_read_data($filename);
    if (isset($exif['Orientation'])) $orientation = $exif['Orientation'];
} else if (preg_match('@\x12\x01\x03\x00\x01\x00\x00\x00(.)\x00\x00\x00@', file_get_contents($filename), $matches)) {
    $orientation = ord($matches[1]);
}
© www.soinside.com 2019 - 2024. All rights reserved.