Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14625 reviews 1734 hosting providers

Questions & Answers

PHP Function to rotate image

May 18, 2012 by darkshark
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 votes
May 18, 2012 by ZakWeb
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 (http://roshanbh.com.np)

  //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);