in reply to Colour Replacement in a PNG

You can do it using Imager. Read "Color Mappings" in Imager::Transformations.

I do this all the time, except I use GD (I don't use Imager).

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: Colour Replacement in a PNG
by Striton_ca (Initiate) on Feb 03, 2004 at 16:36 UTC
    Thank you! Imager documentation leaves much to be desired, but after some tinkering I finally figured out how it worked. It does exactly what I need. Thanks again for your replies!

    Cheers!
    Aaron

      OK. So I can now replace one colour with another. I am now trying to make the replacement colour transparent. Say I want to replace white with red; I have the following code:
      my $redmap = [0 .. 255]; my $blumap = [0 .. 255]; my $grnmap = [0 .. 255]; $blumap->[255] = 0; $grnmap->[255] = 0; $img->map(red=>$redmap, blue=>$blumap, green=>$grnmap);
      This replaces all instances of (255,255,255) with (255,0,0). Now how do I make that red transparent? I thought I would need to do:
      my $redmap = [0 .. 255]; my $blumap = [0 .. 255]; my $grnmap = [0 .. 255]; my $alpha = [0 .. 255]; $blumap->[255] = 0; $grnmap->[255] = 0; $alpha->[0] = 255; $img->map(red=>$redmap, blue=>$blumap, green=>$grnmap, alpha=>$alpha);
      But that doesn't do anything. I like Imager for it's flexibility, but I am really getting frustrated with the documentation. Any help would be greatly appreciated.

      Cheers!
      Aaron