2012-04-23 2 views
0

전 몇 달 전에 온라인 커뮤니티에서 업로드 된 사진의 EXIF ​​데이터를 읽는 방법을 썼습니다. 그림에서 방향을 얻은 후에 파일을 올바른 방향으로 회전 시켰습니다. 내 스크립트에서 짧은 부분 만 :업로드 된 사진을 올바른 방향으로 회전시키는 신뢰할 수있는 방법은 무엇입니까?

public function rotate($sourceFile, $targetFile, $orienation) 
{ 
    switch($orienation){ 
     case 3: $degrees = '180'; break; 
     case 6: $degrees = '90'; break; 
     case 8: $degrees = '270'; break; 
     default: $degrees = '0'; 
    } 

    $file = $sourceFile . DS . $targetFile; 
    $rotate = GlobalConfig::BIN_IMAGICK_CONVERT . ' -rotate ' . $degrees . ' ' . $file . ' ' . $file; 
    exec($rotate); 
} 

내 스크립트가 작동합니다. 하지만 내 질문은 facebook과 같은 다른 큰 사람들이 업로드 한 사진의 회전을 어떻게 처리할까요? 내 솔루션이 확실히 최선이 아니기 때문에.

+0

당신이 "묻는 무엇을 수행 할 수있는 가장 좋은 방법은 회전 조작 "또는"이미지의 방향을 결정하는 가장 좋은 방법은 무엇입니까? " – DaveRandom

+0

네이티브 [ImageMagick] (http://php.net/manual/fr/book.imagick.php) PHP 확장 –

+0

을 사용할 수 있습니다. 그리고 적어도, 나는'exec()'를' if ($ degrees)'- 이미지를 0도 회전시키는 데 의미가 없음 ... – DaveRandom

답변

1

내가 더 나은 방법은 GD 라이브러리를 사용하는 것입니다 생각, 코드는이

// input 
$image = 'myfile.jpg'; 

//read orientation information from EXIF 

$exif = exif_read_data($filename); 
$ort = $exif['IFD0']['Orientation']; 

//then based on $ort you can determine the rotation degree, 
//check the link below for more info 

//rotation degree 
$degrees = 180; 

// create "image object" 
$source = imagecreatefromjpeg($image) ; 

// rotate 
$rotate = imagerotate($source, $degrees, 0) ; 

// set the header 
header('Content-type: image/jpeg') ; 

// output 
imagejpeg($rotate) ; 

대한 추가 정보를 원하시면 같은 간다 : Exif Orientation Tag

+0

Imagick을 사용할 수도 있음을 잊어 버렸습니다. http://php.net/manual/en/imagick.rotateimage.php – Adi

+0

실례지만, 내 부정확 한 요구 때문이에요. 이 과정의 어려운 부분은 이미지가 어느 방향으로 회전해야 하는지를 알아내는 것입니다. 모든 스마트 폰이나 카메라가 방향을 저장하지 않기 때문입니다. 이 예제와 같은 방향을 읽었습니다 : $ exif = exif_read_data ('image.jpg', 0, true); var_dump ($ exif [ 'IFD0'] [ 'Orientation']); – johchri

+0

@ johchri [이 질문은] (http://stackoverflow.com/questions/6726700/is-it-possible-to-detect-blur-exposure-orientation-of-an-image-programmaticall)을보십시오. – DaveRandom

관련 문제