뿌

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

· 2016-03-17 (목) 10:29:25 · 478

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

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

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

팁게시판

6,077건

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
16-03-02 조회 863
16-01-19 조회 493
15-12-23 조회 646
15-12-08 조회 1,297
14-10-30 조회 2,883
14-06-06 조회 2,293
12-08-30 조회 1,502
12-08-20 조회 1,279
12-07-15 조회 2,699
12-07-13 조회 1,472
12-07-06 조회 1,467
12-06-27 조회 1,022
12-06-23 조회 1,136
12-05-03 조회 3,102
12-04-20 조회 2,046
12-03-29 조회 2,364
12-03-22 조회 2,710
12-03-22 조회 1,455
12-03-21 조회 1,285
12-03-11 조회 1,625
12-03-06 조회 1,899
12-02-22 조회 2,239
12-02-17 조회 1,219
12-02-17 조회 4,263
12-02-14 조회 3,886