Php Gd 旋转图像

Ale*_*art 2 php gd

你好,

我正在尝试围绕中心旋转圆形图像,然后切掉侧面。我看到 imagerotate 函数,但它似乎没有绕中心旋转。

有人有什么建议吗?

谢谢。

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

fed*_*ghe 5

我用下面的代码成功地解决了这个问题

    $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
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。

再见