You had seen varities of source code for rotating images by using jquery, movetools etc., We are having solution in PHP f0r accessing roatating. Is it possible? Yes it’s possible in PHP. GD library in PHP is very much usefull for image pocessing. Below code will help you for image rotation ie., image manipulation. I hope this code will be more usefull for PHP developers to use this code.
<?php
function rotateImage($sourceFile,$destImageName,$degreeOfRotation)
{
$imageinfo=getimagesize($sourceFile);
switch($imageinfo['mime'])
{
//create the image according to the content type
case “image/jpg”:
case “image/jpeg”:
case “image/pjpeg”: //for IE
$src_img=imagecreatefromjpeg(“$sourceFile”);
break;
case “image/gif”:
$src_img = imagecreatefromgif(“$sourceFile”);
break;
case “image/png”:
case “image/x-png”: //for IE
$src_img = imagecreatefrompng(“$sourceFile”);
break;
}
//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);
}
?>
The above function takes takes three argument, first one is the source image to be rotated and the second one is the name of file which is resulted after rotating the original image. And, the last parameter is the degree of the rotation of Image.
In this PHP function, first of all the information about the source image is stored in “$imageinfo” array. The MIME type of the file are stored in “mime” key of the “$imageinfo” array. And then appropriate image resource is created using the proper MIME type. And then, imagerotate() function of PHP is used for the rotation of the image then imagejpeg() is used to output the image to a file.
Example of the rotation of Image using PHP function
Look at the original Image which I’m going to rotate in PHP

Now let’s look at the php code to call the above function see the result of rotated image with that function

<?php rotateImage('girl.jpg','rotated.jpg',90); ?>

<?php rotateImage('girl.jpg','rotated.jpg',-45); ?> Source:http://roshanbh.com.np



Posted in
Tags: