2

你好,

我试图围绕中心旋转一个圆形图像,然后切掉侧面。我看到了 imagerotate 功能,但它似乎没有围绕中心旋转。

有人有什么建议吗?

谢谢你。

更新:由于它是一个圆圈,我想切断边缘并保持我的圆圈尺寸相同。

4

3 回答 3

4

我用下面的代码成功地遇到了这个问题

    $width_before = imagesx($img1);
    $height_before = imagesy($img1);
    $img1 = imagerotate($img1, $angle, $mycolor);

    //but imagerotate scales, so we clip to the original size

    $img2 = @imagecreatetruecolor($width_before, $height_before);
    $new_width = imagesx($img1); // whese dimensions are
    $new_height = imagesy($img1);// the scaled ones (by imagerotate)
    imagecopyresampled(
        $img2, $img1,
        0, 0,
        ($new_width-$width_before)/2,
        ($new_height-$height_before)/2,
        $width_before,
        $height_before,
        $width_before,
        $height_before
    );
    $img1 = $img2;
    // now img1 is center rotated and maintains original size

希望能帮助到你。

再见

于 2011-12-05T00:13:56.443 回答
4

文档说它确实围绕中心旋转。

不幸的是,它还说它将缩放图像以使其仍然适合。这意味着无论你做什么这个函数都会改变你内部圆形图像的大小。

您可以(相对容易地)计算缩小多少,然后预先适当地放大图像。

如果你有可用的 PHP“ImageMagick”函数,你可以使用它们——它们显然不会缩放图像。

于 2009-04-23T09:46:06.757 回答
0

根据 PHP 手册imagerotate()页面:

旋转中心是图像的中心,旋转后的图像会按比例缩小,以便整个旋转后的图像适合目标图像 - 边缘不会被剪裁。

也许图像的可见中心不是实际中心?

于 2009-04-23T09:43:04.283 回答