note 85329 added to function.imagerotate

From: Date: Tue, 26 Aug 2008 08:45:43 +0000
Subject: note 85329 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-143828@lists.php.net to get a copy of this message
I modified cbl25's function to allow it to rotate an image either clock wise or counter clock wise. <?php function rotateImage($image, $direction) { $direction = strtolower($direction); $degrees = $direction == 'cw' ? 270 : ($direction == 'ccw' ? 90 : NULL); if(!$degrees) return $image; $width = imagesx($image); $height = imagesy($image); $side = $width > $height ? $width : $height; $imageSquare = imagecreatetruecolor($side, $side); imagecopy($imageSquare, $image, 0, 0, 0, 0, $width, $height); imagedestroy($image); $imageSquare = imagerotate($imageSquare, $degrees, 0, -1); $image = imagecreatetruecolor($height, $width); $x = $degrees == 90 ? 0 : ($height > $width ? 0 : ($side - $height)); $y = $degrees == 270 ? 0 : ($height < $width ? 0 : ($side - $width)); imagecopy($image, $imageSquare, 0, 0, $x, $y, $height, $width); imagedestroy($imageSquare); return $image; } //Usage $image = rotateImage($image, 'cw'); $image = rotateImage($image, 'ccw'); ?> ---- Server IP: 195.184.96.15 Probable Submitter: 83.91.2.77 ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- https://master.php.net/note/edit/85329 Del: integrated -- https://master.php.net/note/delete/85329/integrated Del: useless -- https://master.php.net/note/delete/85329/useless Del: bad code -- https://master.php.net/note/delete/85329/bad+code Del: spam -- https://master.php.net/note/delete/85329/spam Del: non-english -- https://master.php.net/note/delete/85329/non-english Del: in docs -- https://master.php.net/note/delete/85329/in+docs Del: other reasons-- https://master.php.net/note/delete/85329 Reject -- https://master.php.net/note/reject/85329 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#143828) next »