note 37422 added to function.imagerotate

From: Date: Fri, 14 Nov 2003 10:49:52 +0000
Subject: note 37422 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-60378@lists.php.net to get a copy of this message
For those who don't have imagerotate support in GD, here's probably the fastest way to rotate an image using php and standard GD functions on -90 or +90 degrees; this one draws 4 pixels to rotate fast: //$imagePath - path to your image; function will save rotated image overwriting the old one //$rtt - should be 90 or -90 - cw/ccw function quickRotate($imagePath,$rtt){ if(preg_match("/\.(png)/i", $imagePath)) $src_img=ImageCreateFromPNG($imagePath); elseif(preg_match("/\.(jpg)/i", $imagePath)) $src_img=ImageCreateFromJPEG($imagePath); elseif(preg_match("/\.(bmp)/i", $imagePath)) $src_img=ImageCreateFromWBMP($imagePath); $size=GetImageSize($imagePath); //note: to make it work on GD 2.xx properly change ImageCreate to ImageCreateTrueColor $dst_img=ImageCreate($size[1],$size[0]); if($rtt==90){ $t=0; $b=$size[1]-1; while($t<=$b){ $l=0; $r=$size[0]-1; while($l<=$r){ imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1); imagecopy($dst_img,$src_img,$t,$l,$l,$b,1,1); imagecopy($dst_img,$src_img,$b,$r,$r,$t,1,1); imagecopy($dst_img,$src_img,$b,$l,$l,$t,1,1); $l++; $r--; } $t++; $b--; } } elseif($rtt==-90){ $t=0; $b=$size[1]-1; while($t<=$b){ $l=0; $r=$size[0]-1; while($l<=$r){ imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1); imagecopy($dst_img,$src_img,$t,$r,$l,$t,1,1); imagecopy($dst_img,$src_img,$b,$l,$r,$b,1,1); imagecopy($dst_img,$src_img,$b,$r,$l,$b,1,1); $l++; $r--; } $t++; $b--; } } ImageDestroy($src_img); ImageInterlace($dst_img,0); ImageJPEG($dst_img,$imagePath); } ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37422 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37422&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37422&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60378) next »