php – 更改Imagerotate的旋转中心

Imagerotate使用给定角度(以度为单位)旋转图像.

旋转中心是图像的中心,旋转的图像可以具有与原始图像不同的尺寸.

如何更改旋转中心以协调x_new和y_new并避免自动调整大小?

示例:围绕红点旋转.

最佳答案 想到的第一个想法是移动图像,使其新中心位于x_new,y_new旋转并向后移动.

假设:

0 < x_new < w
0 < y_new < h

伪代码:

new_canter_x = MAX(x_new, w - x_new)
new_center_y = MAX(y_new, h - y_new)

create new image (plain or transparent background):
width = new_canter_x * 2
height = new_center_y * 2

copy your old image to new one to coords:
new_center_x - x_new
new_center_y - y_new

imagerotate the new image.

现在你只需要切掉你感兴趣的部分.

点赞