Set a color as transparent in palette-based image

Posted by NeDark on Stack Overflow See other posts from Stack Overflow or by NeDark
Published on 2010-05-30T14:15:29Z Indexed on 2010/05/30 14:32 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about image