php imagick圆角

    $watermark = new \Imagick();
        $watermark->readImage($avatarpath);
        $watermark->scaleImage(160, 160, true);

        $watermark->setFormat('png');

        $mask = new \Imagick();
        $mask->newImage($watermark->getImageWidth(), $watermark->getImageHeight(), 'none');

   

        $draw = new \ImagickDraw();
        $draw->setFillColor('white');
        $draw->roundRectangle(0, 0, $watermark->getImageWidth() - 1, $watermark->getImageHeight() - 1, $watermark->getImageWidth() / 2, $watermark->getImageHeight() / 2);

        $mask->drawImage($draw);
        $watermark->setImageMatte(1);
        // Apply the mask to the original image
        $watermark->compositeImage($mask, \imagick::COMPOSITE_DSTIN, 0, 0);

 

posted @ 2023-05-12 17:32  newmiracle宇宙  阅读(35)  评论(0编辑  收藏  举报