Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 657221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:47:58+00:00 2026-05-13T22:47:58+00:00

After many hair-pulling frustrations I’ve finally got one version of the PerlMagick module working

  • 0

After many hair-pulling frustrations I’ve finally got one version of the PerlMagick module working with my ActivePerl 5.10.0 build 1005. Now I’m playing with it to do some very basic color substitution.

I already can substitute 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’m wondering if I can replace any color that is not black with the color blue. I hope and think there’s some idiomatic syntax to achieve this, so I’m asking for a quick help 🙂 Any ideas?

Thanks like always for any guidance/suggestions/comments 🙂

UPDATE

@rjh, thank YOU for the code and the information 🙂 I tried ’em all with a little adpations and they all work like charm!

That older version cannot be run. My PerlMagick is 6.5.4, but with a little adapation, it also works like so:

  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');

Well, of course I like your second version. It’s super. It’s the very syntax that I was expecting, hehe 🙂

And the first commandline version also works well although I was not expecting this version.

Again, thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T22:47:59+00:00Added an answer on May 13, 2026 at 10:47 pm

    In ImageMagick 6.3.7-10 and up, you can use the ‘+’ form of opaque to invert the colour selection. This command will convert anything that is NOT black, with blue:

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

    In Perl this can be done via:

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

    If you only have an older version it can still be done, via

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

    …which I will leave for you to convert to the Perl API.

    Source: http://www.imagemagick.org/Usage/color/#opaque – a useful resource for ImageMagick operations in general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After many hours of hair pulling, I look to stackoverflow to help me solve
After many hours, I finally realize that I am working correctly with the Cache
After many hours of research and tinkering, I've finally managed to get backbone.js routes
i am looking for dropdown menu ( onlcick ) after many searches, finally i
After one week searching and converting many algorithm from other language into php to
After many months of postponing it, this week, I finally started using a new
We recently started working with XML files, after many years of experience with the
After many years of working on a general-purpose C++ library using the Microsoft MSVC
After many practice websites, I have finally made a website that is published. The
I have finally managed to launch my app after many days of trying but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.