旋转图像*无*调整大小

问题描述:

我想旋转图像(用户定义的旋转角度),但不会使图像变小。旋转图像*无*调整大小

  1. 是什么已经发生,节约了阴影区域为更小的图像
  2. 是我想什么,虚线是新的图像大小。

该服务器的PHP 5.3+。链接,代码和解释都非常受欢迎。

+2

这将有助于了解你是如何旋转图像。 – JJJ 2012-02-28 11:36:32

+1

查看http://php.net/manual/en/function.imagerotate.php并签出'imagerotateEquivalent()'函数。我认为像这样的东西可以用来实现这样的事情。 – Cyclonecode 2012-02-28 11:58:51

+0

似乎你“做了很多谷歌搜索”,但没有想到通过'imagerotate'手册页上的评论。 – 2012-02-28 12:18:00

这不是完整的答案,但我会采取四角作为坐标旋转他们的角度,然后计算新的边界框基于新坐标的范围。 (假设坐标原点在左下角)。

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]) 

这可能是一种方法。计算对角线宽度。

Check this image for the formula

PHP有一个平方根函数:http://se2.php.net/manual/en/function.sqrt.php 这样,你就应该有,你可以申请变换图像的对角线宽度。