이미지를 회전하고 저장하려고합니다. 회전은 EXIF 데이터를 기반으로합니다. 나는 모두가 주위에 검은 색 테두리를주고 다음, 시도 :PHP - GD로 이미지를 회전하면 검정색 테두리가 나타납니다.
을 경우이 같은 원래의 모습 :
$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);
을하지만 난 그냥 작동 얻을 수없는 것. 누구든지 이걸 도와 줄 수 있니?
테스트 해 주셔서 감사합니다. 이는 내가 작업하고있는 응용 프로그램이 다른 곳의 이미지를 변경한다는 것을 의미 할 수 있습니다. 나는이 코드가 어디에서 작동하는지 알기 위해 노력할 것입니다 :-) –