use strict; use warnings; use GD; my $in_file = qw[foo.png]; my $ni_file = $in_file.".ni.png"; my $image = GD::Image->new($in_file); my $i = 0; my $t = $image->colorsTotal(); while($i < $t) { my( @c ) = $image->rgb( $i ); my $g = ( $c[0] + $c[1] + $c[2] ) / 3; # Color::Calc::grey $image->colorDeallocate($i); $image->colorAllocate( $g, $g, $g ); $i++; } write_file( $ni_file, $image->png ); sub write_file { my $i = shift; open DISPLAY, ">$i" or die "can't clobber $i $!"; binmode DISPLAY; print DISPLAY @_; close DISPLAY; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert image to greyscale (color to black and white)
by tachyon (Chancellor) on Dec 21, 2003 at 12:10 UTC | |
by bart (Canon) on Dec 22, 2003 at 10:33 UTC | |
|
Re: convert image to greyscale (color to black and white)
by b10m (Vicar) on Dec 21, 2003 at 11:44 UTC | |
|
Re: convert image to greyscale (color to black and white)
by liz (Monsignor) on Dec 21, 2003 at 11:31 UTC | |
by tachyon (Chancellor) on Dec 21, 2003 at 12:27 UTC | |
by Razorbeard (Initiate) on Jan 05, 2009 at 17:40 UTC | |
|
Re: convert image to greyscale (color to black and white)
by theAcolyte (Pilgrim) on Dec 31, 2003 at 14:25 UTC |