/* This function is provided by php manual (function.imagerotate.php)
It's a workaround to enables image rotation on distributions which do not
use the bundled gd library (e.g. Debian, Ubuntu).
*/
public static function imageRotate($src_img, $angle, $colBlack = 0)
{
if (!imageistruecolor($src_img)) {
$w = imagesx($src_img);
$h = imagesy($src_img);
$t_im = imagecreatetruecolor($w, $h);
imagecopy($t_im, $src_img, 0, 0, 0, 0, $w, $h);
$src_img = $t_im;
}
$src_x = imagesx($src_img);
$src_y = imagesy($src_img);
if ($angle == 180) {
$dest_x = $src_x;
$dest_y = $src_y;
} elseif ($src_x <= $src_y) {
$dest_x = $src_y;
$dest_y = $src_x;
} elseif ($src_x >= $src_y) {
$dest_x = $src_y;
$dest_y = $src_x;
}
$rotate = imagecreatetruecolor($dest_x, $dest_y);
imagealphablending($rotate, false);
switch ($angle) {
case 270:
for ($y = 0; $y < $src_y; $y++) {
for ($x = 0; $x < $src_x; $x++) {
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
}
}
break;
case 90:
for ($y = 0; $y < $src_y; $y++) {
for ($x = 0; $x < $src_x; $x++) {
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
}
}
break;
case 180:
for ($y = 0; $y < $src_y; $y++) {
for ($x = 0; $x < $src_x; $x++) {
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
}
}
break;
default:
$rotate = $src_img;
}
return $rotate;
}