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

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

· 9년 전 · 452

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

그누보드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;
 }

댓글 작성

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

로그인하기

게시글 목록

번호 제목
8050
8048
19969
19968
19967
19966
19965
19964
19963
19962
19961
28345
31017
19960
19959
19958
19957
8039
8035
8029
28344
28339
8019
28338
8017
8010
8007
8004
8003
28332
28322
7999
28317
20956
7992
20945
28314
20936
20931
7986
20925
7982
7979
7978
7975
28307
7973
7966
28305
7963
28300
7961
28297
28295
7959
19948
19947
28292
31016
19946
19945
28286
7958
7956
7952
7946
28285
28283
19943
7944
7936
7931
28279
24666
24663
7928
7923
19941
28274
28257
28249
28248
7914
7912
7911
20912
7908
31755
28233
28232
28228
7903
28217
20900
24662
20891
20882
19936
20853
31011