note 82261 added to function.imagerotate

From: Date: Thu, 03 Apr 2008 05:23:52 +0000
Subject: note 82261 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-137879@lists.php.net to get a copy of this message
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; } } ?> ---- Server IP: 212.124.37.9 Probable Submitter: 84.57.72.249 ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- https://master.php.net/note/edit/82261 Del: integrated -- https://master.php.net/note/delete/82261/integrated Del: useless -- https://master.php.net/note/delete/82261/useless Del: bad code -- https://master.php.net/note/delete/82261/bad+code Del: spam -- https://master.php.net/note/delete/82261/spam Del: non-english -- https://master.php.net/note/delete/82261/non-english Del: in docs -- https://master.php.net/note/delete/82261/in+docs Del: other reasons-- https://master.php.net/note/delete/82261 Reject -- https://master.php.net/note/reject/82261 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137879) next »