note 93692 deleted from function.imagerotate by cmb
| From: | cmb@php.net | Date: | Mon, 22 Aug 2016 10:25:09 +0000 |
| Subject: | note 93692 deleted from function.imagerotate by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206363@lists.php.net to get a copy of this message | ||
Note Submitter: beau at dragonflydevelopment dot com
----
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");
?>