旋转图像*而不*调整大小

I would like to rotate an image (with a user-defined angle of rotation), but without making the image smaller.

  1. is what happens already, saving the shaded area as a smaller image
  2. is what I would like, the dashed line being the new image size.

The server has PHP 5.3+. Links, code and explanations all very welcome.

This is not complete answer but I would take the four corners as coordinates rotate them by your angle and then calculate the new bounding box based on the extent of the new coordinates. (assuming coordinates with origin on the bottom left).

corners = rotate_each ( [(left,top) (left,bottom), (right,top), (right,bottom)], angle)
new_bb_left = min([corners[0].x, corners[1].x, corners[2].x, corners[3].x])
new_bb_right = max([corners[0].x, corners[1].x, corners[2].x, corners[3].x])
new_bb_bottom = min([corners[0].y, corners[1].y, corners[2].y, corners[3].y])
new_bb_top = max([corners[0].y, corners[1].y, corners[2].y, corners[3].y])

This could be a way to do it. Calculate the diagonal width.

Check this image for the formula

PHP has a Square root function: http://se2.php.net/manual/en/function.sqrt.php In that way you should have the diagonal width which you could apply on the transformed image.