Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP GD:黑色背景透明_Php_Cd - Fatal编程技术网

PHP GD:黑色背景透明

PHP GD:黑色背景透明,php,cd,Php,Cd,我的问题是,图片是透明的(应该是透明的),但“混合模式”所在的部分仍然有点黑,但不应该是 图1: 图2: 图3: 以及输出 您可以在输出中看到黄色部分周围的黑色小圆圈 我的代码: $dst = imagecreatetruecolor(1000, 1000); imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 0, 0, 0, 127)); foreach ($images as $value) { /

我的问题是,图片是透明的(应该是透明的),但“混合模式”所在的部分仍然有点黑,但不应该是

  • 图1:
  • 图2:
  • 图3:
以及输出

您可以在输出中看到黄色部分周围的黑色小圆圈

我的代码:

$dst = imagecreatetruecolor(1000, 1000);

    imagefill($dst, 0, 0, imagecolorallocatealpha($dst, 0, 0, 0, 127));

    foreach ($images as $value) {
        // IMPROVE!
        $value[1] = (500 - $value[1]);
        $value[2] = (500 - $value[2]);

        $src = imagecreatefrompng("result/$value[0].png");

        imagealphablending($src, false);
        imagesavealpha($dst, true);

        // BLEND MODE
        imagecolortransparent($src, imagecolorat($src, 0, 0));

        imagecopy($dst, $src, $value[1], $value[2], 0, 0, imagesx($src), imagesy($src));
        imagedestroy($src);
    }

    $dst = imagecropauto($dst, IMG_CROP_DEFAULT);

    imagepng($dst, sprintf('images/64/%s_%d.png', $name, $rotation));
    imagedestroy($dst
所以我希望任何人都能帮忙

问候。

“图像3”是屏幕混合图像。 由于GD库中没有函数,您应该自己创建或使用ImageMagick

使用GD的每个像素的混合代码示例:

$src = imagecreatefrompng("result/$value[0].png");
$rgba = imagecolorat($src, 0, 0);
$color = imagecolorsforindex($src, $rgba);

//2-type blend mode
if($color['alpha'] == 0){
    //no-alpha image, Screen Blend
    for($y = $value[2]; $y < imagesy($dst); $y++){
        if($y - $value[2] > imagesy($src) - 1) break;
        if($y < 0) continue;
        for($x = $value[1]; $x < imagesx($dst); $x++){
            if($x - $value[1] > imagesx($src) - 1) break;
            if($x < 0) continue;
            $rgb_dst = imagecolorat($dst, $x, $y);
            $colors_dst = imagecolorsforindex($dst, $rgb_dst);

            $rgb_src = imagecolorat($src, $x - $value[1], $y - $value[2]);
            $colors_src = imagecolorsforindex($src, $rgb_src);

            $r = $colors_dst['red'] + $colors_src['red'] - ($colors_dst['red'] * $colors_src['red']) / 255;
            $g = $colors_dst['green'] + $colors_src['green'] - ($colors_dst['green'] * $colors_src['green']) / 255;
            $b = $colors_dst['blue'] + $colors_src['blue'] - ($colors_dst['blue'] * $colors_src['blue']) / 255;
            $alpha = $colors_dst['alpha'];

            imagesetpixel($dst, $x, $y, imagecolorallocatealpha($dst, $r, $g, $b, $alpha));
        }
    }
}else{
    //legacy
    imagealphablending($src, false);
    imagecolortransparent($src, imagecolorat($src, 0, 0));
    imagecopy($dst, $src, $value[1], $value[2], 0, 0, imagesx($src), imagesy($src));
}
imagedestroy($src);
$src=imagecreatefrompng(“结果/$value[0].png”);
$rgba=imagecolorat($src,0,0);
$color=imagecolorsforindex($src,$rgba);
//2型混合模式
如果($color['alpha']==0){
//无alpha图像,屏幕混合
对于($y=$value[2];$yimagesy($src)-1)中断;
如果($y<0)继续;
对于($x=$value[1];$ximagesx($src)-1)中断;
如果($x<0)继续;
$rgb_dst=imagecolorat($dst,$x,$y);
$colors_dst=imagecolorsforindex($dst,$rgb_dst);
$rgb_src=imagecolorat($src,$x-$value[1],$y-$value[2]);
$colors\u src=imagecolorsforindex($src,$rgb\u src);
$r=$colors_dst['red']+$colors_src['red']-($colors_dst['red']*$colors_src['red'])/255;
$g=$colors\U dst['green']+$colors\U src['green']-($colors\U dst['green']*$colors\U src['green'])/255;
$b=$colors_dst['blue']+$colors_src['blue']-($colors_dst['blue']*$colors_src['blue'])/255;
$alpha=$colors_dst['alpha'];
imagesetpixel($dst,$x,$y,imagecolorallocatealpha($dst,$r,$g,$b,$alpha));
}
}
}否则{
//遗产
imagealphablending($src,false);
imagecolortransparent($src,imagecolorat($src,0,0));
imagecopy($dst,$src,$value[1],$value[2],0,0,imagesx($src),imagesy($src));
}
(1)(src);
结果:

您是否尝试过将图像3透明化,以黄色发光而不是黑色背景?“我猜在你应用它之前,图3看起来是这样的吗?”拉斯克莱特说,“是的,我试过了,但没用。”。