note 82261 deleted from function.imagerotate by danbrown

From: Date: Tue, 02 Dec 2008 14:57:45 +0000
Subject: note 82261 deleted from function.imagerotate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147530@lists.php.net to get a copy of this message
Note Submitter: Dominik Scholz - info at HAM&SPAM dot go4u dot de ---- I took the previous mentioned code and optimized it a little bit. It does some speed improvements for me, but I did no exact measurements. Instead of decrementing by 1 in each cycle of the for-loops, I did the decrementing once before the loops. Maybe further improvements can be made... <?php if(!function_exists("imagerotate")) { function imagerotate($src_img, $angle) { $src_x = imagesx($src_img); $src_y = imagesy($src_img); if ($angle == 180) { $dest_x = $src_x; $dest_y = $src_y; } elseif (($angle == 90) || ($angle == 270)) { $dest_x = $src_y; $dest_y = $src_x; } else { return $src_img; } $rotate=imagecreatetruecolor($dest_x,$dest_y); imagealphablending($rotate, false); switch ($angle) { case 270: $dest_x--; for ($y = 0; $y < $src_y; $y++) for ($x = 0; $x < $src_x; $x++) imagesetpixel($rotate, $dest_x - $y, $x, imagecolorat($src_img, $x, $y)); break; case 90: $dest_y--; for ($y = 0; $y < $src_y; $y++) for ($x = 0; $x < $src_x; $x++) imagesetpixel($rotate, $y, $dest_y - $x, imagecolorat($src_img, $x, $y)); break; case 180: $dest_x--; $dest_y--; for ($y = 0; $y < $src_y; $y++) for ($x = 0; $x < $src_x; $x++) imagesetpixel($rotate, $dest_x - $x, $dest_y - $y, imagecolorat($src_img, $x, $y)); break; } return $rotate; } } ?>

« previous php.notes (#147530) next »