PHP - Rotate image on reference point

无人久伴 提交于 2021-01-29 03:42:35

问题


I am wondering if it is possible to rotate an image using a reference point.

For example, rotating this image by 30 degrees:

instead of having:

I would like to have:

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.


回答1:


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


来源:https://stackoverflow.com/questions/36603061/php-rotate-image-on-reference-point

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!