0

I am currently using imagerotate() available in php GD to let user rotate images. Whenever user rotates like 45 degree, 75 degree etc, background color is added to make image have rectangle shape. The more the number of time user rotates,the bigger the image size and the wider the background color area.

$image = imagerotate($image,45, 0xFFFFFF);

Is there anyway in php gd to rotate image with free degree(eg: 45 degrees,75 degrees, 306 degrees) without adding any background image or without increasing file image?

Edit: I get this error: "Fatal error: Allowed memory size of 33554432 bytes exhausted" when image size is getting bigger and white area is getting wider. That's why I want to know any other way to rotate image.

Thank you.

ATZ
  • 353
  • 2
  • 7
  • 18
  • the image file always rect, how you imaginate that image size fill not be changed, when you rotate image ? (if image is not square) – zb' Oct 14 '12 at 09:13
  • 1
    Have you considered keeping the original image untouched, tracking the sum of all rotations and rotating the original image only once by that total amount? – DCoder Oct 14 '12 at 09:19
  • @DCoder, thx...I did but user need to see the changes as he changes the rotation degree. That's why I cannot do that way. – ATZ Oct 14 '12 at 13:54
  • Yes, you can. Take original image, rotate by `x` degrees, save to temp file, display. New rotation? Take original image, rotate by `x + y` degrees, save to temp file, display. Another new rotation? Rotate original by `x + y + z` degrees, where's the problem? – DCoder Oct 14 '12 at 14:00

2 Answers2

0

Try to set the background to black, which would be 0's, and also use JPEG, which is a compressed image format. This MAY help - I have not tested myself though. Try it.

Example:

$image = imagerotate($image, 45, 0x000000);
NYCBilly
  • 870
  • 1
  • 8
  • 11
  • Wow... Sorry... It is actually adding pixels, so physically, it really is expected to add weight to the file. – NYCBilly Oct 14 '12 at 09:20
0

I was about to write some code here with the same answer of DCoder.

That is the best process you can apply since it only requires one transformation.

Bye

PatomaS
  • 1,603
  • 18
  • 25