【问题标题】:Copy an Image with Drop Shadow and Tranparent Background复制带有阴影和透明背景的图像
【发布时间】:2011-10-10 03:45:31
【问题描述】:

我尝试复制具有投影(即 Alpha 通道)和透明背景的 PNG 图像。但是,生成的图像用黑色绘制阴影和透明背景。我试过imagecopy和imagecopymerge;两者都没有产生有效的结果,这与原始图像不同。

Preview of the images.

$src = imagecreatefrompng('img_box3-bg.png');

/* Using imagecopy. */
$dest = imagecreatetruecolor(116, 100);
imagecopy($dest, $src, 0, 0, 0, 0, 116, 100);
imagepng($dest, 'img_box3-bg.imagecopy.png');
imagedestroy($dest);

/* Using imagecopymerge. */
$dest2 = imagecreatetruecolor(116, 100);
imagecopymerge($dest2, $src, 0, 0, 0, 0, 116, 100, 100);
imagepng($dest2, 'img_box3-bg.imagecopymerge.png');
imagedestroy($dest2);

imagedestroy($src);

帮助?先谢谢了。

【问题讨论】:

    标签: php image-processing image-manipulation


    【解决方案1】:

    类似这样的:

    $src = imagecreatefrompng('img_box3-bg.png');
    
    /* Using imagecopy. */
    $dest = imagecreatetruecolor(116, 100);
    
    // this is new
    imagesavealpha($dest, true);
    $transparent = imagecolorallocatealpha($dest, 0, 0, 0, 127);
    imagefill($dest, 0, 0, $transparent);
    
    imagecopy($dest, $src, 0, 0, 0, 0, 116, 100);
    
    header('Content-Type: image/png');
    imagepng($dest);
    imagedestroy($dest);
    

    【讨论】:

    • 我认为你的意思是$dest 而不是上面sn-p 中的$img。不幸的是,这并没有奏效。再次查看链接/预览页面:我添加了一张使用建议方法完成的新图片。
    • @Siku-Siku.Com 更改了示例,这在我的测试机器上运行。希望对您有所帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2012-02-08
    • 2012-10-15
    • 2019-12-13
    相关资源
    最近更新 更多