简体   繁体   English

在基于调色板的图像中将颜色设置为透明

[英]Set a color as transparent in palette-based image

I want to convert a alpha transparent png image to palette based png image. 我想将alpha透明png图像转换为基于调色板的png图像。

In GD I can do it easy: 在GD中,我可以轻松做到这一点:

    // We have already the image loaded in $source_img
    $w=200; $h=200; // We supose that img dimensions are 200x200
    $img = imagecreatetruecolor($w, $h); // New black image
    list($r, $g, $b) = array(200, 200, 200); // Some color that doesn't appear in image to avoid conflict 
    $color = imagecolorallocate($img, $r, $g, $b); 
    imagefill($img, 0, 0, $color);  // Fill the black image with the chosen color.
    imagecolortransparent($img, $color);  // Set the chosen color as transparent
    $res = imagecopyresampled($img, $source_img, 0, 0, 0, 0, $w, $h, $w, $h);

But in Imagick I don't know how set a color as transparent (imagecolortransparent() in GD). 但是在Imagick中,我不知道如何将颜色设置为透明(GD中的imagecolortransparent())。 I have spent hours searching on the internet, but the help in the php site isn't very comphrensive and there are many undocumented functions. 我花了数小时在Internet上搜索,但是php站点中的帮助不是很全面,并且有许多未记录的功能。

Thanks. 谢谢。

On the command line I would do something like this: 在命令行上,我将执行以下操作:

convert test.png -transparent-color white PNG8:converted.png

But there seems to be a problem in some IM versions with this type of conversion, I found this usergroup post by some guy who seems to have similiar problems: http://studio.imagemagick.org/pipermail/magick-users/2009-May/022534.html 但是在某些IM版本中,使用这种类型的转换似乎存在问题,我发现这个用户组帖子是由某个似乎有类似问题的家伙撰写的: http : //studio.imagemagick.org/pipermail/magick-users/2009- May / 022534.html

Are you using the command line when working with IM or do you use the PHP module ( http://de.php.net/manual/en/book.imagick.php )? 使用IM时是在使用命令行还是使用PHP模块( http://de.php.net/manual/zh/book.imagick.php )?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM