donkey111111 2018-03-11 16:51
浏览 84

PHP GD - blendmode alpha计算

I have the problem if I change my calculation for alpha in imagecolorallocatealpha is it wrong.

Image 1: enter image description here

Image 2: enter image description here

Image 3: enter image description here

Image 4: enter image description here

Image 5: enter image description here

The pictures from 1 - 3 are put together and look like this:

enter image description here

If pictures 4 and 5 are added, it looks like this:

enter image description here

You can now see the golden scales and the gray scales on the body, but that's wrong. The gray scales on the body should not be there.

In reality, the dragon should look like this:

enter image description here

The gray scales on the body should be bright and the golden scales should remain as they are.

@Syscall already helped with the "alpha" function in this thread and it works good but now we think the "blendmode" function is wrong.

function blendmode($dst, $src)
{
    $w = imagesx($src);
    $h = imagesy($src);

    for ($x = 0; $x < $w; $x++) {
        for ($y = 0; $y < $h; $y++) {
            $rgbDst = imagecolorsforindex($dst, imagecolorat($dst, $x, $y));
            $rgbSrc = imagecolorsforindex($src, imagecolorat($src, $x, $y));

            $r = min($rgbSrc['red'] + $rgbDst['red'], 255);
            $g = min($rgbSrc['green'] + $rgbDst['green'], 255);
            $b = min($rgbSrc['blue'] + $rgbDst['blue'], 255);

            imagesetpixel($src, $x, $y, imagecolorallocatealpha($src, $r, $g, $b, 204 / 255 * 105));
        }
    }

    return $src;
}

This is how the dragon looks like with buggy "blendmode" function:

enter image description here

  • 写回答

1条回答 默认 最新

  • dqsxsmi3704 2018-03-19 23:25
    关注

    first at all I would recommend you not sticking on the builtin Graphic Libraries for php.

    I would recommend you the ImageMagik (Imagick) or Intervention (http://image.intervention.io/).

    They are a lot more powerfull libraries.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题