views:

62

answers:

1

Hello there!

I want to convert a alpha transparent png image to palette based png image.

In GD I can do it easy:

    // 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). 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.

Thanks.

A: 

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

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 )?

Max
I use the PHP module, yes. I will check if I can use the command line. Thanks.
NeDark