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

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

· 9년 전 · 451

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

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

댓글 작성

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

로그인하기

게시글 목록

번호 제목
28213
31006
7898
7897
19935
7892
7885
31005
28209
7880
7877
7871
7865
7862
7858
7852
19933
19931
19928
19927
31003
19920
28206
19918
28200
7850
19916
28180
28165
19911
7842
7838
7830
7818
28150
19906
19905
19903
19901
19900
28145
7815
31002
7803
7799
7785
19898
7780
7779
7777
7776
7775
7758
19893
19892
19891
20850
19885
7752
7747
7738
19883
7735
28139
7734
7731
7725
7717
19879
7715
7710
19858
7709
7703
28134
28129
7694
7690
28125
7672
7660
28111
19857
19856
7658
28106
28098
7655
28095
7651
19851
7646
19850
24661
28089
7633
7623
28087
28085
7620