Page 1 of 1

Problem while rotating an image in PHP

Posted: Thu Apr 29, 2010 1:57 am
by siji86
Hi,
I have a PHP script that rotates an image and currently i have given the rotation angle as 90 degrees, but the problem is when i rotate the image by 30 degrees, or 45 degrees, the image gets distorted and gets smaller and smaller.
Here is the function
function rotateLeft(){
$rotate = imagerotate($this->image, $this->leftDegree, 0);
imagejpeg($rotate,$this->imagePath, 100);
}

Does Anybody know why this is happening, i don't want the image to be distorted.

Thanks,
Eliza
:D

Re: Problem while rotating an image in PHP

Posted: Thu Apr 29, 2010 10:24 am
by wanger220
I think the problem is that when you rotate the image at an angle, the overall width and height becomes larger than that of the original image. It's likely that the php rotate function automatically scales the image to preserve the original image dimensions, and that's why your images are shrinking.

You probably need to use php's resize function (along with a bit of math) to fix this. I'm sure someone else who is more skilled can provide an accurate solution.

As for the distortion issue, browser manipulation of images is always sketchy. I work primarily with photos and the only advice I've ever heard is not to rely on browsers for anything image related.

Re: Problem while rotating an image in PHP

Posted: Thu Apr 29, 2010 11:56 am
by mikosiko
plenty of answers and examples that could help you

http://php.net/manual/en/function.imagerotate.php

Re: Problem while rotating an image in PHP

Posted: Fri Apr 30, 2010 10:04 am
by katierosy
Although already answered. This page has some image rotating functions(http://php.net/manual/en/function.imagerotate.php)

Re: Problem while rotating an image in PHP

Posted: Mon May 03, 2010 12:06 am
by siji86
thanx for the reply