PHP - 在参考点上旋转图像
问题描述:
我想知道是否可以使用参考点旋转图像.
I am wondering if it is possible to rotate an image using a reference point.
例如,将此图像旋转 30 度:
For example, rotating this image by 30 degrees:
而不是:
我想要:
表示在左下角旋转图像.
which means rotating the image on the bottom-left point.
如果需要,我会将矩形重叠到原始图像上,然后根据需要旋转它.
I would do this overlapping the rectangle to the original image if needed, and rotating it as needed only after.
答
ImageMagick 扩展可以做到这一点,使用 DISTORTION_SCALEROTATETRANSLATE 选项.您可能需要稍微调整坐标和角度以满足您的需要.
The ImageMagick extension can do this, using the DISTORTION_SCALEROTATETRANSLATE option. You might need to tweak the coordinates and angle a bit to fit your needs.
<?php
$im = new Imagick('sample.png');
$args = array(
0, // X-point
300, // Y-point
1, // Scale
-45, // Rotation
);
$im->distortImage(Imagick::DISTORTION_SCALEROTATETRANSLATE, $args, false);
$im->setImageFormat('png');
file_put_contents('rotated.png', (string) $im);