뿌

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

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

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

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

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

토크

3,606건

오픈소스 관련 다양한 이야기를 자유롭게 나눠요

+
제목 글쓴이 날짜 조회
16-05-16 조회 2,324
16-05-15 조회 1,547
16-05-12 조회 1,397
16-05-11 조회 1,195
16-05-11 조회 1,301
16-05-11 조회 1,446
16-05-04 조회 1,384
16-05-01 조회 1,216
16-04-28 조회 1,494
16-04-27 조회 1,939
16-04-01 조회 1,966
16-04-12 조회 1,271
16-03-31 조회 1,314
16-03-29 조회 1,679
16-03-11 조회 2,115
16-03-10 조회 1,352
16-03-09 조회 1,818
16-03-09 조회 1,254
16-02-18 조회 1,969
16-02-16 조회 1,654
16-02-03 조회 1,478
16-02-02 조회 1,870
16-03-21 조회 1,393
16-03-21 조회 1,227
16-03-19 조회 1,285
16-03-19 조회 1,387
16-03-17 조회 1,129
16-03-17 조회 1,030
16-03-14 조회 1,261
16-03-13 조회 1,092