相关疑难解决方法(0)

PHP GD如何圆形裁剪3个方形图像并合并为1个图像保持透明度

我有2个源图像,我想:

  1. 对每个图像进行圆形裁剪,使圆的外部透明
  2. 将所有图像合并/复制回目标透明图像.

我尝试了很多例子,但似乎无法保持最终图像的透明度.

我正在努力实现这样的目标: 在此输入图像描述

这是我得到的输出的一个例子: 在此输入图像描述

这是我的circle_crop函数:

    function create_circle( $img_path ) {
    // Attribution: by NerdsOfTech

    // Step 1 - Start with image as layer 1 (canvas).
    if (! $img1 = $this->imageCreateFromAny( $img_path )) {
        return FALSE;
    }

    $x=imagesx($img1);
    $y=imagesy($img1);


    // Step 2 - Create a blank image.
    $img2 = imagecreatetruecolor($x, $y);

    $bg = imagecolorallocate($img2, 255,0,255, 127); // wierdo pink background
    // $bg = imagecolorallocate($img2, 0, 0, 0, 127 ); // white background

    imagefill($img2, 0, 0, $bg);
    imagecolortransparent($img2, …
Run Code Online (Sandbox Code Playgroud)

php png transparency gd

2
推荐指数
1
解决办法
2893
查看次数

标签 统计

gd ×1

php ×1

png ×1

transparency ×1