Problem while rotating an image in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Problem while rotating an image in PHP

Post 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
wanger220
Forum Newbie
Posts: 19
Joined: Tue Feb 02, 2010 8:44 pm

Re: Problem while rotating an image in PHP

Post 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.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Problem while rotating an image in PHP

Post by mikosiko »

plenty of answers and examples that could help you

http://php.net/manual/en/function.imagerotate.php
katierosy
Forum Commoner
Posts: 27
Joined: Wed Apr 07, 2010 8:39 am

Re: Problem while rotating an image in PHP

Post by katierosy »

Although already answered. This page has some image rotating functions(http://php.net/manual/en/function.imagerotate.php)
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Re: Problem while rotating an image in PHP

Post by siji86 »

thanx for the reply
Post Reply