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; }