note 93692 added to function.imagerotate

From: Date: Wed, 23 Sep 2009 09:13:35 +0000
Subject: note 93692 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-160966@lists.php.net to get a copy of this message
I believe the rotateImage function below is incorrect. The 180 rotation was actually doing a vertical mirror instead of rotating 180 degrees. The change was $i to $width - $i. <?php function rotateImage($img, $rotation) { $width = imagesx($img); $height = imagesy($img); switch($rotation) { case 90: $newimg= @imagecreatetruecolor($height , $width );break; case 180: $newimg= @imagecreatetruecolor($width , $height );break; case 270: $newimg= @imagecreatetruecolor($height , $width );break; case 0: return $img;break; case 360: return $img;break; } if($newimg) { for($i = 0;$i < $width ; $i++) { for($j = 0;$j < $height ; $j++) { $reference = imagecolorat($img,$i,$j); switch($rotation) { case 90: if(!@imagesetpixel($newimg, ($height - 1) - $j, $i, $reference )){return false;}break; case 180: if(!@imagesetpixel($newimg, $width - $i, ($height - 1) - $j, $reference )){return false;}break; case 270: if(!@imagesetpixel($newimg, $j, $width - $i, $reference )){return false;}break; } } } return $newimg; } return false; } ?> you can call it this way: <?php $img = rotateImage($imagetorotate,"degrees"); ?> ---- Server IP: 208.69.120.35 Probable Submitter: 24.143.67.178 ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- https://master.php.net/note/edit/93692 Del: integrated -- https://master.php.net/note/delete/93692/integrated Del: useless -- https://master.php.net/note/delete/93692/useless Del: bad code -- https://master.php.net/note/delete/93692/bad+code Del: spam -- https://master.php.net/note/delete/93692/spam Del: non-english -- https://master.php.net/note/delete/93692/non-english Del: in docs -- https://master.php.net/note/delete/93692/in+docs Del: other reasons-- https://master.php.net/note/delete/93692 Reject -- https://master.php.net/note/reject/93692 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160966) next »