2016-11-16 1 views
3

이미지를 회전하고 저장하려고합니다. 회전은 EXIF ​​데이터를 기반으로합니다. 나는 모두가 주위에 검은 색 테두리를주고 다음, 시도 :PHP - GD로 이미지를 회전하면 검정색 테두리가 나타납니다.

enter image description here

을 경우이 같은 원래의 모습 :

$orientation = array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[@exif_read_data($imagePath)['Orientation'] ?: 0]; 

$source = imagecreatefromjpeg($imagePath); 
$resource = imagerotate($source, $orientation, 0); 
imagejpeg($resource, $image, 100); 

나는 또한 imagealphablending($resource, true);을 추가하는 시도하고 Black background when rotating image with PHP에 제안 된대로 imagesavealpha($resource, true);,하지만 아무 소용이 없습니다; 국경이 남아있다.

은 그 때 나는 imagecreatetruecolor()으로 이미지를 만드는 시도 :

$imageSizes = getimagesize($image); 
$oldWidth = $imageSizes[0]; 
$oldHeight = $imageSizes[1]; 

$orientation = array_values([0, 0, 0, 180, 0, 0, -90, 0, 90])[@exif_read_data($image)['Orientation'] ?: 0]; 

$source = imagecreatefromjpeg($imagePath); 
$resource = imagerotate($source, $orientation, 0); 

$newWidth = $oldWidth; 
$newHeight = $oldHeight; 

if ($orientation !== 180 && $orientation !== 0) { 
    $newWidth = $oldHeight; 
    $newHeight = $oldWidth; 
} 

$imageResized = imagecreatetruecolor($newWidth, $newHeight); 

imagecopyresampled ($imageResized, $resource, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight); 
imagejpeg($imageResized, $image, 100); 

을하지만 난 그냥 작동 얻을 수없는 것. 누구든지 이걸 도와 줄 수 있니?

답변

1

이 당신을 도울 수도 있고,

내가 코드를 테스트하고 이미지를 사용하여, 또한 나 enter image description here

을 위해 잘 작동 한이 늘 나에게 문제를 제공하지 않을 수 있습니다 .. 답변 밤은 . 내가 볼 수

, 당신의 결과 이미지, 검은 색 테두리와 그 .. 왼쪽 테두리를 보면, 상위 개 croped되어 원래와 diference이 있고, 그 차이는

+0

테스트 해 주셔서 감사합니다. 이는 내가 작업하고있는 응용 프로그램이 다른 곳의 이미지를 변경한다는 것을 의미 할 수 있습니다. 나는이 코드가 어디에서 작동하는지 알기 위해 노력할 것입니다 :-) –

3

내가 '검은 국경 오늘 Windows 용 PHP에서이 문제를 발견했습니다. 테두리는 0도 또는 360도 회전 할 때만 추가되는 것처럼 보입니다. 나는 180도 회전으로 국경을 얻지 못한다. 따라서 방위가 0이 아닌지 확인하고 필요한 경우 회전 만하십시오.

... if ($orientation !== 0) $resource = imagerotate($source, $orientation, 0); else $resource = $source; end ...

+0

또는 450도 회전 (묻지 않음)하면 동일한 경계가 나타납니다. –

관련 문제