php读取exif定向返回'';而它应该是8(90度)


php reading exif orientation returns '...' while it should be 8 (90 degrees)

我有一个可以上传照片的网站。当它们以肖像拍摄时,它们以向左90度的横向显示,因此它们必须向右旋转90度。我的脚本:

            $uploadedfile = $_FILES['file']['tmp_name'];
            $rotated = false;
            $exif = exif_read_data($uploadedfile);
            $orientation = $exif['IFD0']['Orientation'];
            switch($orientation) {
            case 3:
                $src = imagerotate($src, 180, 0);
                break;
            case 6:
                $src = imagerotate($src, -90, 0);
                    $rotated = true;
                break;
            case 8:
                $src = imagerotate($src, 90, 0);
                $rotated = true;
                break;
            }

但$orientation的价值是"…"。我正在上传我的三星galaxy s6的照片,但galaxy s3的照片有同样错误的方向。有人能帮我解决这个问题吗?

php > $exif = exif_read_data('20160305_073024.jpg');
php > print_r($exif);
Array
(
    [FileName] => 20160305_073024.jpg
    [FileDateTime] => 1458474774
    [FileSize] => 148254
    [FileType] => 2
    [MimeType] => image/jpeg
    [SectionsFound] => ANY_TAG, IFD0, EXIF
    [COMPUTED] => Array
        (
            [html] => width="600" height="860"
            [Height] => 860
            [Width] => 600
            [IsColor] => 1
            [ByteOrderMotorola] => 1
            [ApertureFNumber] => f/2.8
            [UserComment] => User comments
            [UserCommentEncoding] => ASCII
        )
    [Make] => SAMSUNG
    [Model] => GT-N7100
    [Orientation] => 1
    [XResolution] => 72/1
    [YResolution] => 72/1
    [ResolutionUnit] => 2
    [Software] => N7100XXUFNG4
    [DateTime] => 2016:03:05 07:30:24
    [Exif_IFD_Pointer] => 190
    [ExposureTime] => 1/100
    [FNumber] => 14/5
    [ExposureProgram] => 3
    [ISOSpeedRatings] => 100
    [ExifVersion] => 0220
    [DateTimeOriginal] => 2016:03:05 07:30:24
    [DateTimeDigitized] => 2016:03:05 07:30:24
    [ComponentsConfiguration] => 
    [ExposureBiasValue] => 0/1
    [MeteringMode] => 2
    [FocalLength] => 5/2
    [UserComment] => ASCIIUser comments
    [FlashPixVersion] => 0100
    [ColorSpace] => 1
    [ExifImageWidth] => 600
    [ExifImageLength] => 860
    [ExposureMode] => 0
    [WhiteBalance] => 0
    [SceneCaptureType] => 0
    [ImageUniqueID] => S5K6A3
)

在CCD_ 2返回的数组中没有CCD_。所以你应该用替换你的$orientation

$orientation = $exif['Orientation'];