PHP 버전이 낮아 imagerotate() 함수가 없을때 대신 사용하는 함수

· 9년 전 · 798

--------------------------------------

그누보드4에서 모바일 파일첨부시 세로사진이 옆으로 누워버리길래..

찾다가 기존에 쓰는 방법인 imagerotate()함수가 php버전이 낮으면 작동이 안되고 찾을수 없다고 나온다..

그래서 열심히 구글링 후 다른 방법을 찾았기에.. 여기에 남김..

중복이면 죄송.

--------------------------------------

 

function rotateImage($img, $rotation) {
 $width = imagesx($img);
 $height = imagesy($img);
 switch($rotation) {
 case 90: $newimg= @imagecreatetruecolor($height , $width );break;
 case 180: $newimg= @imagecreatetruecolor($width , $height );break;
 case 270: $newimg= @imagecreatetruecolor($height , $width );break;
 case 0: return $img;break;
 case 360: return $img;break;
 }
 if($newimg) {
 for($i = 0;$i < $width ; $i++) {
 for($j = 0;$j < $height ; $j++) {
 $reference = imagecolorat($img,$i,$j);
 switch($rotation) {
 case 90: if(!@imagesetpixel($newimg, $j, $width - $i, $reference )){return false;}break;
 case 180: if(!@imagesetpixel($newimg, $width - $i, ($height - 1) - $j, $reference )){return false;}break;
 case 270: if(!@imagesetpixel($newimg, ($height - 1) - $j, $i, $reference )){return false;}break;
 }
 }
 } return $newimg;
 }
 return false;
 }

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

토크

개발과 관련된 어떤 얘기도 괜찮습니다.

+
제목 글쓴이 날짜 조회
9년 전 조회 1,426
9년 전 조회 1,845
9년 전 조회 1,095
9년 전 조회 1,595
9년 전 조회 1,003
9년 전 조회 1,743
9년 전 조회 1,429
9년 전 조회 1,243
9년 전 조회 1,637
9년 전 조회 1,159
9년 전 조회 984
9년 전 조회 1,063
9년 전 조회 1,170
9년 전 조회 887
9년 전 조회 799
9년 전 조회 1,015
9년 전 조회 869
9년 전 조회 890
9년 전 조회 995
9년 전 조회 981
9년 전 조회 983
9년 전 조회 820
9년 전 조회 1,191
9년 전 조회 921
9년 전 조회 821
9년 전 조회 812
9년 전 조회 792
9년 전 조회 1,257
9년 전 조회 1,289
9년 전 조회 1,241
🐛 버그신고