]> git.imager.perl.org - imager.git/commitdiff
add a recipe to the cookbook
authorTony Cook <tony@develop-help.com>
Fri, 13 Jul 2012 09:53:44 +0000 (19:53 +1000)
committerTony Cook <tony@develop-help.com>
Fri, 13 Jul 2012 09:53:44 +0000 (19:53 +1000)
it's been a while, and the intuition was interesting

lib/Imager/Cookbook.pod

index 9fcf6f29194871a21e1e5d763a2bc1bd4b10d0a0..ad7af17e46bfaa4ee218c2c4e06f06dc2e8cfce2 100644 (file)
@@ -432,6 +432,23 @@ in pixels per centimeter, you would do:
 
 Keywords: DPI
 
+=head1 IMAGE MANIPULATION
+
+=head2 Replacing a color with transparency
+X<replacing colors>
+
+To replace a color with transparency you can use the
+L<Imager::Filters/difference()> method.
+
+  # make a work image the same size as our input
+  my $work = Imager->new(xsize => $in->getwidth, ysize => $in->getheight,
+                         channels => $in->getchannels);
+  # and fill it with the colour we want transparent
+  $work->box(filled => 1, color => $color);
+
+  # get an image with that colour replaced with transparent black
+  my $out = $work->difference(other => $in);
+
 =head1 AUTHOR
 
 Tony Cook <tony@develop-help.com>