note 37422 deleted from function.imagerotate by aidan

From: Date: Mon, 04 Oct 2004 07:03:46 +0000
Subject: note 37422 deleted from function.imagerotate by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-77884@lists.php.net to get a copy of this message
Note Submitter: sergei at gmx dot net ---- 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); }

« previous php.notes (#77884) next »