How to replace any color that is not a specific color using PerlMagick?

After many frustrations with hair, I finally got one version of the PerlMagick module that works with my ActivePerl 5.10.0 build 1005. Now I play with it to make a very basic color change.

I can already replace one color, say black, with another, say blue, using the following code:

#!perl
 use strict;
 use warnings;
 use Image::Magick;

  my $image = Image::Magick->new;
  $image->Read('color-test.bmp');
  $image->Opaque(fill => 'blue', color => 'black');
  $image->Write('result.bmp');

But I am wondering if I can replace any color that is not black with blue. I hope and think that this requires some kind of idiomatic syntax, so I ask for urgent help :) Any ideas?

Thanks, as always, for any recommendations / suggestions / comments :)

UPDATE

@rjh, thank YOU for the code and information :) I tried them with small advertisements and they all work like a charm!

. PerlMagick - 6.5.4, :

  use strict;
  use warnings;
  use Image::Magick;

  my $image = Image::Magick->new;
  $image->Read('color-test.bmp');
     $image->Transparent(color=>'black');
     $image->Colorize(fill=>'blue');
     $image->Composite(image=>$image);
     $image->Write('result.bmp');

, , . . , , -:)

, .

!

+3
1

ImageMagick 6.3.7-10 "+" . , , :

convert in.gif  -fill blue +opaque black   out.gif

Perl :

$image->Opaque(fill => 'blue', color => 'black', invert => 'True');

, ,

convert out.gif \
      \( +clone -matte -transparent black \
         -fill blue  -colorize 100% \) \
      -composite    in.gif

... API Perl.

: http://www.imagemagick.org/Usage/color/#opaque - ImageMagick .

+10

Source: https://habr.com/ru/post/1734752/


All Articles