note 93636 deleted from function.imagerotate by cmb
| From: | cmb@php.net | Date: | Mon, 22 Aug 2016 09:41:40 +0000 |
| Subject: | note 93636 deleted from function.imagerotate by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-206360@lists.php.net to get a copy of this message | ||
Note Submitter: ewald at dutchvisual dot nl
----
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");
?>