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

时间:2012-02-28 11:34:53

标签: php

我想旋转图像(使用用户定义的旋转角度),但不会缩小图像。

  1. 已经发生的事情,将阴影区域保存为较小的图像
  2. 是我想要的,虚线是新的图像尺寸。
  3. 服务器的PHP为5.3+。链接,代码和解释都非常受欢迎。

3 个答案:

答案 0 :(得分:2)

这不是完整的答案,但我会采用四个角,坐标按角度旋转它们,然后根据新坐标的范围计算新的边界框。 (假设左下角有原点的坐标)。

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

答案 1 :(得分:1)

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

Check this image for the formula

PHP具有平方根函数:http://se2.php.net/manual/en/function.sqrt.php 这样你就可以得到你可以在变换后的图像上应用的对角线宽度。

答案 2 :(得分:0)