note 50105 deleted from function.imagerotate by danbrown

From: Date: Tue, 02 Dec 2008 15:01:32 +0000
Subject: note 50105 deleted from function.imagerotate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147542@lists.php.net to get a copy of this message
Note Submitter: jonathan AT sharpmedia DOT net ---- This method rotates an image in 90 degree increments (eg count should be between 1 and 3) and avoids the problems of image scaling that imageRotate has... <?php function rotateImage($src, $count = 1, $quality = 95) { if (!file_exists($src)) { return false; } list($w, $h) = getimagesize($src); if (($in = imageCreateFromJpeg($src)) === false) { echo "Failed create from source<br>"; return false; } $angle = 360 - ((($count > 0 && $count < 4) ? $count : 0 ) * 90); if ($w == $h || $angle == 180) { $out = imageRotate($in, $angle, 0); } elseif ($angle == 90 || $angle == 270) { $size = ($w > $h ? $w : $h); // Create a square image the size of the largest side of our src image if (($tmp = imageCreateTrueColor($size, $size)) == false) { echo "Failed create square trueColor<br>"; return false; } // Exchange sides if (($out = imageCreateTrueColor($h, $w)) == false) { echo "Failed create trueColor<br>"; return false; } // Now copy our src image to tmp where we will rotate and then copy that to $out imageCopy($tmp, $in, 0, 0, 0, 0, $w, $h); $tmp2 = imageRotate($tmp, $angle, 0); // Now copy tmp2 to $out; imageCopy($out, $tmp2, 0, 0, ($angle == 270 ? abs($w - $h) : 0), 0, $h, $w); imageDestroy($tmp); imageDestroy($tmp2); } elseif ($angle == 360) { imageDestroy($in); return true; } imageJpeg($out, $src, $quality); imageDestroy($in); imageDestroy($out); return true; } ?>

« previous php.notes (#147542) next »