note 93636 added to function.imagerotate

From: Date: Sun, 20 Sep 2009 11:35:35 +0000
Subject: note 93636 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-160864@lists.php.net to get a copy of this message
This function will rotate the image. The image will be resampled completely. <?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, $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: 91.199.167.18 Probable Submitter: 83.85.0.162 ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- https://master.php.net/note/edit/93636 Del: integrated -- https://master.php.net/note/delete/93636/integrated Del: useless -- https://master.php.net/note/delete/93636/useless Del: bad code -- https://master.php.net/note/delete/93636/bad+code Del: spam -- https://master.php.net/note/delete/93636/spam Del: non-english -- https://master.php.net/note/delete/93636/non-english Del: in docs -- https://master.php.net/note/delete/93636/in+docs Del: other reasons-- https://master.php.net/note/delete/93636 Reject -- https://master.php.net/note/reject/93636 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#160864) next »