2016-06-29 2 views
0

사용자가 프로필 사진을 업로드 할 수있는 웹 앱을 만들었습니다. 사용자가 모바일 카메라를 사용하여 이미지를 캡처하면 방향이 변경됩니다. 다음 코드를 사용하여 해결하기 위해 관리 : PHP가 올바른 방향으로 이미지 업로드 - imagerotate가 iPhone에서 작동하지 않습니다.

    $path[0] = $_FILES['image_upload_file']['tmp_name']; 

       $exif = exif_read_data($path[0]); 
       // $exif['Orientation'] = 6; 

       if(isset($exif['Orientation'])){ 

        $image = imagecreatefromjpeg($path[0]); 
        file_put_contents("img_data.txt",print_r($image,true)); 

        $ort = $exif['Orientation']; 
        switch($ort) 
        { 

         case 3: // 180 rotate left 
          $image = imagerotate($image, 180,0); 
          break; 


         case 6: // 90 rotate right 
          file_put_contents("img_before.txt",print_r($exif,true)); 
          $image = imagerotate($image, -90, 0); 
          file_put_contents("img_after.txt",print_r($ort,true)); 
          break; 

         case 8: // 90 rotate left 
          $image = imagerotate($image, 90, 0); 
          break; 
        } 
        imagejpeg($image, $path[0], 90); 
       } 

그러나

PHP read_exif_data and Adjust Orientation에서이 코드를있어, 이미지가 안드로이드 장치 또는 컴퓨터에서 캡처 한 경우에만 작동합니다. iPhone 장치에서 이미지를 캡처하면 작동하지 않습니다.

디버깅하는 동안 나는 $image = imagerotate($image, -90, 0); 아이폰에 문제가 있음을 발견했습니다. 이 행이 실행되지 않았으므로 확실히 말할 수 있습니다 (img_after.txt가 생성 된 위치에 생성되지 않았기 때문에).

file_put_contents("img_after.txt",print_r($ort,true)); 

제발 제안하십시오!

UPDATE :

EXIF ​​데이터가 아이폰에서 읽어 안드로이드에서 읽을

Array 
(
    [FileName] => phpYBaC5W 
    [FileDateTime] => 1467207697 
    [FileSize] => 1430214 
    [FileType] => 2 
    [MimeType] => image/jpeg 
    [SectionsFound] => ANY_TAG, IFD0, EXIF 
    [COMPUTED] => Array 
     (
      [html] => width="3264" height="2448" 
      [Height] => 2448 
      [Width] => 3264 
      [IsColor] => 1 
      [ByteOrderMotorola] => 1 
     ) 

    [Orientation] => 6 
    [Exif_IFD_Pointer] => 38 
    [ColorSpace] => 1 
    [ExifImageWidth] => 3264 
    [ExifImageLength] => 2448 
) 

EXIF ​​데이터 :

Array 
(
    [FileName] => phpMQHUgW 
    [FileDateTime] => 1467207789 
    [FileSize] => 1842753 
    [FileType] => 2 
    [MimeType] => image/jpeg 
    [SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS, INTEROP 
    [COMPUTED] => Array 
     (
      [html] => width="3264" height="1836" 
      [Height] => 1836 
      [Width] => 3264 
      [IsColor] => 1 
      [ByteOrderMotorola] => 0 
      [ApertureFNumber] => f/2.4 
      [Thumbnail.FileType] => 2 
      [Thumbnail.MimeType] => image/jpeg 
      [Thumbnail.Height] => 288 
      [Thumbnail.Width] => 512 
     ) 

    [ImageWidth] => 3264 
    [ImageLength] => 1836 
    [Make] => SAMSUNG 
    [Model] => SM-G7102 
    [Orientation] => 6 
    [XResolution] => 72/1 
    [YResolution] => 72/1 
    [ResolutionUnit] => 2 
    [Software] => G7102DDUBOB1 
    [DateTime] => 2016:06:29 19:12:59 
    [YCbCrPositioning] => 1 
    [Exif_IFD_Pointer] => 238 
    [GPS_IFD_Pointer] => 870 
    [THUMBNAIL] => Array 
     (
      [ImageWidth] => 512 
      [ImageLength] => 288 
      [Compression] => 6 
      [Orientation] => 6 
      [XResolution] => 72/1 
      [YResolution] => 72/1 
      [ResolutionUnit] => 2 
      [JPEGInterchangeFormat] => 1018 
      [JPEGInterchangeFormatLength] => 5829 
     ) 

    [ExposureTime] => 1/17 
    [FNumber] => 240/100 
    [ExposureProgram] => 2 
    [ISOSpeedRatings] => 1000 
    [ExifVersion] => 0220 
    [DateTimeOriginal] => 2016:06:29 19:12:59 
    [DateTimeDigitized] => 2016:06:29 19:12:59 
    [ComponentsConfiguration] => 
    [ShutterSpeedValue] => 405/100 
    [ApertureValue] => 252/100 
    [BrightnessValue] => -169/100 
    [ExposureBiasValue] => 0/10 
    [MaxApertureValue] => 253/100 
    [MeteringMode] => 2 
    [LightSource] => 0 
    [Flash] => 0 
    [FocalLength] => 293/100 
    [MakerNote] =>  0100      Z @   P        
    [FlashPixVersion] => 0100 
    [ColorSpace] => 1 
    [ExifImageWidth] => 3264 
    [ExifImageLength] => 1836 
    [InteroperabilityOffset] => 840 
    [SensingMethod] => 2 
    [SceneType] => 
    [ExposureMode] => 0 
    [WhiteBalance] => 0 
    [FocalLengthIn35mmFilm] => 31 
    [SceneCaptureType] => 0 
    [ImageUniqueID] => E08QLGI01CH 
    [GPSVersion] => 
    [InterOperabilityIndex] => R98 
    [InterOperabilityVersion] => 0100 
) 

나는 이미지를 회전하는 코드를 건너 뛸 경우, 아이폰을 포함한 모든 휴대 전화에서 잘 작동합니다.

+0

는 PHP가 클라이언트에서 실행되고 있지 않은 점을 감안 :

는 여기에 긴 스레드가 SO 읽고 싶어 할 수 있었다. 디버깅을하고 다르게 보내지는 것을 찾으십시오. –

+0

클라이언트 운영 체제가 서버와 관련이있는 이유는 무엇입니까? '$ exif [ '오리엔테이션']'이 iPhone에서 제대로 설정되어 있습니까? – apokryfos

+0

예. $ exif [ 'Orientation']은 iPhone 또는 Andoird에서 업로드 할 때 올바르게 설정됩니다. –

답변

0

이것은 이미지를 업로드 할 때 파일에서 EXIF ​​데이터를 제거하거나 최소한 이미지 비트를 제거하여 개인 정보를 보호하기위한 iPhone의 "기능"입니다.

이전에는 Javascript에서 해당 데이터를 가져 와서 백엔드로 전달할 수있는 해킹이 있었지만 더 이상 나타나지 않습니다.

나는 더 이상 iPhone 사용자가 아니지만 새로운 버전의 iOS에서 수정되었다는 추측과보고가있었습니다.하지만 여전히 사용자 기반의 큰 부분 해당 데이터를 제공하지 못할 수도 있습니다. 문제는 결함이있다 (즉, 그것은 안드로이드 아니에요하거나 실행 IOS) Image upload from iphone strips exif data

+1

iPhone에서도 EXIF ​​데이터를 수신 할 수 있습니다. 콘텐츠도 게시했습니다. 유일한 문제는 $ image = imagerotate ($ image, -90, 0); 왜 제대로 실행되지 않는지 잘 모릅니다. 내가 아는 한 올바르게,이 진술은 서버 측에서 실행되고 $ image는 유효한 이미지이기도합니다. 올바른 결과를 주기로되어 있습니다. 그렇지 않습니까? –

관련 문제