테스트 사이트 - 개발 중인 베타 버전입니다

이미지 업로드 하고 나서 사이즈 변경하는 코드인데 문제가 있습니다 채택완료

choco5958 4년 전 조회 1,122
아래 코드로 업로드 한 이미지 사이즈를 변경하면 사진이 90도 돌아가지는데 어떻게 하면될까요??

//파라미터(원본이미지, 바뀔이미지, 화질 (0 ~100) , 사이즈 width, height)
//파일 업로드 완료됐다라는 가정하에 진행 (move_uploaded_file)

$source_img		= $file_path."/".$file_nm1; //업로드 된 이미지
$destination_img = $file_path."/"."64_".$file_nm1; //앞에 64_ 를 붙히고 저장
            
compress($source_img, $destination_img , 90, 64,64);
// 파일 사이즈 및 용량 변경
function compress($file, $destination, $quality, $w, $h) {

    $info = getimagesize($file);

    $width = $info[0];
    $height = $info[1];

    if ($info['mime'] == 'image/jpeg') 
        $image = imagecreatefromjpeg($file);

    elseif ($info['mime'] == 'image/gif') 
        $image = imagecreatefromgif($file);

    elseif ($info['mime'] == 'image/png') 
        $image = imagecreatefrompng($file);

    $dst = imagecreatetruecolor($w, $h);
    imagecopyresampled($dst, $image, 0, 0, 0, 0, $w, $h, $width, $height);
    $result = imagejpeg($dst, $destination, $quality);

	return $result;
}

 

 

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
해피정
4년 전

https://sir.kr/g5_plugin/6165  이것을 추천합니다

https://www.happyjung.com/lecture/3017  는 위 팁을 적용한 후기(?) 입니다

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인