I just found that there is no function to rotate an images in PHP. So I wrote this little function. It rotates an image 90 degrees to the right. It creates a new image with the same colors but possibly different indexes.
function ImageRotate($oldimage)
{
$newx = ImageSY($oldimage);
$newy = ImageSX($oldimage);
$newimage = ImageCreate($newx, $newy);
$color_indexes = array();
for($x = 0; $x<$newx; $x++) {
for($y = 0; $y<$newy; $y++) {
$px = ImageColorAt($oldimage, $y, $x);
if(!in_array($px, array_keys($color_indexes))) {
$colors = ImageColorsForIndex($oldimage, $px);
$newpx = ImageColorAllocate($newimage, $colors["red"], $colors["green"], $colors["blue"]);
$color_indexes[$px] = $newpx;
} else {
// translate the color index to the new image
$newpx = $color_indexes[$px];
}
ImageSetPixel($newimage, $x, $y, $newpx);
}
}
return($newimage);
}