PHP Function to rotate image

asked May 18, 2012 in General by darkshark (1,500 points)
Hello there
Does anyone know a PHP function that I can use to rotate an image? I need to rotate some images in my website using PHP and I don’t know how to. Any help will be very much appreciated.

Thank you

1 Answer

0 like 0 dislike
answered May 18, 2012 by ZakWeb (3,880 points)
Function to rotate image using GD library of PHP
function rotateImage($sourceFile,$destImageName,$degreeOfRotation)
  //function to rotate an image in PHP
  //developed by Roshan Bhattara (

  //get the detail of the image
   //create the image according to the content type
   case "image/jpg":
   case "image/jpeg":
   case "image/pjpeg": //for IE
    case "image/gif":
        $src_img = imagecreatefromgif("$sourceFile");
    case "image/png":
        case "image/x-png": //for IE
        $src_img = imagecreatefrompng("$sourceFile");
  //rotate the image according to the spcified degree
  $src_img = imagerotate($src_img, $degreeOfRotation, 0);
  //output the image to a file
  imagejpeg ($src_img,$destImageName);