use strict; use warnings; use feature 'say'; use open IO => ':raw'; use GD; use Convert::Color; sub desaturate { local $" = ','; my @HSV = Convert::Color-> new( "rgb8:@_" )-> as_hsv-> hsv; $HSV[ 1 ] *= 0.7; return Convert::Color-> new( "hsv:@HSV" )-> as_rgb8-> rgb8 } my $gd = GD::Image-> newFromPngData( scalar qx/convert rose: png:-/, 1 ); for my $y ( 0 .. $gd-> height - 1 ) { for my $x ( 0 .. $gd-> width - 1 ) { my $packed_rgb = $gd-> getPixel( $x, $y ); my @RGB = reverse unpack 'C3', pack 'L', $packed_rgb; $packed_rgb = unpack 'L', pack 'C3x', reverse desaturate( @RGB ); $gd-> setPixel( $x, $y, $packed_rgb ) } } open my $fh, '>', 'desaturated_rose.png' or die; binmode $fh; print $fh $gd-> png; close $fh;