note 28052 deleted from function.imagerotate by sniper

From: Date: Mon, 26 May 2003 03:14:51 +0000
Subject: note 28052 deleted from function.imagerotate by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49004@lists.php.net to get a copy of this message
Note Submitter: php@laer.nu ---- I wrote a function that will rotate an image by 90, 180 or 270 degrees without chopping off part of the picture if it's not square. If you've tried to use imagerotate() on a rectangular image, you'll know what I'm talking about. It may not be the best way to do this, but it gets the job done. Use it like so: $dst_img = rotate(src_img, 90); where $src_img is an image resource and 90 is the number if degrees to rotate. Note: This function ONLY works with 90, 180, or 270 degrees. function rotate($src_img, $degrees = 90) { $degrees %= 360; if ($degrees == 0) { $dst_img = $src_img; } Elseif ($degrees == 180) { $dst_img = imagerotate($src_img, $degrees, 0); } Else { $width = imagesx($src_img); $height = imagesy($src_img); if ($width > $height) { $size = $width; } Else { $size = $height; } $dst_img = imagecreatetruecolor($size, $size); imagecopy($dst_img, $src_img, 0, 0, 0, 0, $width, $height); $dst_img = imagerotate($dst_img, $degrees, 0); $src_img = $dst_img; $dst_img = imagecreatetruecolor($height, $width); if ((($degrees == 90) && ($width > $height)) || (($degrees == 270) && ($width < $height))) { imagecopy($dst_img, $src_img, 0, 0, 0, 0, $size, $size); } if ((($degrees == 270) && ($width > $height)) || (($degrees == 90) && ($width < $height))) { imagecopy($dst_img, $src_img, 0, 0, $size - $height, $size - $width, $size, $size); } } return $dst_img; }

« previous php.notes (#49004) next »