PHP - 在参考点上旋转图像 [英] PHP - Rotate image on reference point
本文介绍了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);
这篇关于PHP - 在参考点上旋转图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文