[SOLVED] Colorize(blend=>string) [as RGB pctgs; e.g., blend=>'100/0/0']

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

[SOLVED] Colorize(blend=>string) [as RGB pctgs; e.g., blend=>'100/0/0']

Post by E. Fudd Wabbitwy » 2019-09-21T11:10:53-07:00

I've only been able to find one example:

Code: Select all

blend->'0x20'
from a user's comment on a different method.

I want to read in an existing PNG image (which has transparency) and make the whole thing transparent.

I guess that it should be doable with $image->Colorize(fill=>\@transp_pixelpkt,blend=>string), but I cannot find information about the format for "string".

Searches of the forum and the imagemagick.org website for +blend +string turned up nothing.

Can someone please help?

Thank you.

(Note: It's possible that '0x20' would be interpreted as "0x00000020", hex with the first three '00' pairs associated with 'r,g,b' blend percentages respectively, and '20' referring to 'something or other' to do with 'alpha'.)
Last edited by E. Fudd Wabbitwy on 2019-09-23T19:12:38-07:00, edited 3 times in total.

User avatar
fmw42
Posts: 25546
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Colorize(blend=>string) [what's the format of string?]

Post by fmw42 » 2019-09-21T11:27:33-07:00

Many ways. Here are two in command line:

Code: Select all

convert image.png -alpha transparent result.png
or

Code: Select all

convert image.png -channel a -evaluate set 0 +channel result.png
See
https://imagemagick.org/Usage/canvas/#blank_pick

snibgo
Posts: 12145
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colorize(blend=>string) [what's the format of string?]

Post by snibgo » 2019-09-21T11:45:19-07:00

On $image->Colorize, see http://www.imagemagick.org/script/comma ... p#colorize . Perhaps the blend parameter corresponds to the command-line "value".

But "-colorize" can't create transparency.
snibgo's IM pages: im.snibgo.com

E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

Re: Colorize(blend=>string) [what's the format of string?]

Post by E. Fudd Wabbitwy » 2019-09-21T12:29:26-07:00

@snibgo
https://imagemagick.org/script/perl-mag ... manipulate
lists Method: Colorize() with two parameters, 'fill', and 'blend'

Parameter 'fill' corresponds to the command line's 'value': as you say, it appears to be a color[1], but I looked in vain for a parallel for 'blend'.

@Fred
On the same note, without some kind of "Guidemap" informing PerlMagick users how the command-line translates to Image::Magick calls, the best we can do is guess.

This brings me full circle, I think. I started here by asking if anyone knew of a way to get the Perl modules (Magick.pm and its cohorts) to cough up information about their own methods and parameters.

I Feel It In My Bones that PerlMagick is--some-how--"making command-line calls" to ImageMagick, and if I could--only--find the Rosetta stone for how it is translating PerlMagick methods before doing so, my chatter here would be much reduced.

Notes:
[1] I say "appears" because the writer of the Colorize() method in PerlMagick COULD have added Transparency to what's acceptable to 'fill' and then stripped it out and processed it differently before sending it on to ImageMagick.

snibgo
Posts: 12145
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Colorize(blend=>string) [what's the format of string?]

Post by snibgo » 2019-09-21T12:38:18-07:00

E. Fudd Wabbitwy wrote:Parameter 'fill' corresponds to the command line's 'value': as you say, it appears to be a color[1], ...
I'm not saying that. I expect perl Colorize "fill" corresponds to the CLI "-fill", which is a colour, and perl Colorize "blend" corresponds to CLI "-colorize value", where value is typically a single number but can be three comma-separated numbers.

But I don't use perl or PerlMagick.
snibgo's IM pages: im.snibgo.com

E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

Re: Colorize(blend=>string) [what's the format of string?]

Post by E. Fudd Wabbitwy » 2019-09-22T11:55:24-07:00

I realized that, having just installed ImageMagick from source and having not removed the compilation working-directory, I had the source to ImageMagick right in front of me!

Here's what I did, in Ubuntu Linux:

Code: Select all

% find ~/ImageMagick-7.0.8-65/ -type f -exec grep -i Colorize\( {} \; -print | grep \.[ch]$
to identify all the .c and .h files containing "[Cc]olorize(", and I judged
~/ImageMagick-7.0.8-65/MagickCore/fx.c
to be most likely.

Inside it, I found this clue:

Code: Select all

ColorizeImage() blends the fill color with each pixel in the image.
%  A percentage blend is specified with opacity.  Control the application
%  of different color components by specifying a different percentage for
%  each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
From that, I guessed the format might be blend=>'pct/pct/pct':

Code: Select all

$image->Colorize(fill=>'red',blend=>'100/100/100');
which did the fill I wanted, but as you guessed, did not affect any transparent pixels.

snibgo
Posts: 12145
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: [Solved] Colorize(blend=>string) [as RGB pctgs; e.g., blend=>'100/0/0']

Post by snibgo » 2019-09-22T14:53:32-07:00

When searching source code, I suggest you start with PerlMagick\Magick.xs. That shows the call to ColorizeImage(...) A grep of magickcore\*.h finds that function in fx.h.
snibgo's IM pages: im.snibgo.com

E. Fudd Wabbitwy
Posts: 27
Joined: 2019-09-18T08:46:14-07:00
Authentication code: 1152

Re: [SOLVED] Colorize(blend=>string) [as RGB pctgs; e.g., blend=>'100/0/0']

Post by E. Fudd Wabbitwy » 2019-09-24T06:17:48-07:00

I took your advice and visited, and I recall that I'd been there before, hunting for 'blend', but didn't see the forest for the trees.

It is exactly--half of--what I wanted:
The Definitive List of ImageMagick Methods That Can Be Called From PerlMagick/Image::Magick Code.

I still need, though, to hunt down The Definitive Formats of the Parameters That Go With Them (strings, especially).

Post Reply