note 85187 modified in function.imagerotate by felipe

From: Date: Wed, 20 Aug 2008 02:50:36 +0000
Subject: note 85187 modified in function.imagerotate by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143659@lists.php.net to get a copy of this message
Here is a simple function to rotate a non-square image 90 degrees clockwise. <?php function rotateImage($imageResource) { $width = imagesx($imageResource); $height = imagesy($imageResource); $side = $width > $height ? $width : $height; $squareImage = imagecreatetruecolor($side, $side); imagecopy($squareImage,$imageResource,0,0,0,0,$width,$height); $squareImage = imagerotate($squareImage,270,0,-1); $imageResource = imagecreatetruecolor($height, $width); $x = $height > $width ? 0 : $side - $height; imagecopy($imageResource,$squareImage,0,0,$x,0,$height,$width); return $imageResource; } ?> --was-- Here is a simple function to rotate a non-square image 90 degrees clockwise. <?php function rotateImage($imageResource) { $width = imagesx($imageResource); $height = imagesy($imageResource); $side = $width > $height ? $width : $height; $squareImage = imagecreatetruecolor($side, $side); imagecopy($squareImage,$imageResource,0,0,0,0,$width,$height); $squareImage = imagerotate($squareImage,270,0,-1); $imageResource = imagecreatetruecolor($height, $width); $x = $height > $width ? 0 : $side - $height; imagecopy($imageResource,$squareImage,0,0,$x,0,$height,$width); return $imageResource; } ?> http://php.net/manual/en/function.imagerotate.php

« previous php.notes (#143659) next »