use Image::Magick; my $img = Image::Magick->new; $img->Read('./img.jpg' ); $img->Quantize( colors => 18 ); $img->Set( type => 'Palette' ); $img->Write('./out.png'); # I can check that it has been reduced... my $out = Image::Magick->new; $out->Read('./out.png'); $out->Get( colors ) == 18 or die;