dongyin2643 2011-09-10 13:53
浏览 82

IMG_FILTER_COLORIZE问题

I already got some great advice on the forums how to get the colorize function using imagefilter IMG_FILTER_COLORIZE.

The problem is that it doesn't work as I want it to work, the link below illustrates it best: http://expromo.pl/klienci/imagefilter/

I have a transparent png containing some kind of shape. I want to:

  • Change the color of the shape just as Photoshop Layer Settings / Colorize would
  • Preserve the transparency
  • Save it as another PNG file

Here is my code:

$im = imagecreatefrompng('image.png');
imagealphablending($im, false);

if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0,0,255,0))
{
    imagepng($im, 'image-new.png');
    imagedestroy($im);
}

On the link above: http://expromo.pl/klienci/imagefilter/

The first image is what I have. The second image is what I get, and the third image is what I want to get.

Big thanks in advance.

  • 写回答

1条回答 默认 最新

  • douaoli5328 2011-12-07 04:57
    关注

    You must add imagesavealpha($im, true); so the alpha channel will be saved on the new image.

    $im = imagecreatefrompng('image.png');
    imagealphablending($im, false);
    
    imagesavealpha($im, true);
    
    if($im && imagefilter($im, IMG_FILTER_COLORIZE, 0,0,255,0)) {
        imagepng($im, 'image-new.png');
        imagedestroy($im);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答