Windows equivalent of: -fill "black(25%)" -colorize 100

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Hi everyone,

Im using Windows Shell with ImageMagick-6.9.3-Q16-HDRI.

Can someone help me convert the following to equivalent windows code:

-fill "black(25%)" -colorize 100

I got this working as expected:

-fill black -colorize 100%%

...but I need to make the black partially transparent. I attempted this but with error:

-fill "black(25%%)" -colorize 100%%

Any help is appreciated.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

There are no shades of black, only shades of gray. In gray shades, black is gray(0) or gray(0%), though you can use the color name black.

So to make 25% opaque gray between black and white use the following.

Code: Select all

-fill "gray(25%)" -colorize 100
the 100 does not need %. If in bat file, then

Code: Select all

-fill "gray(25%%)" -colorize 100

Note that -colorize will not add transparency, that is, the following does not work to make 25% transparent black (alpha values are only expressed as fractions. See https://www.imagemagick.org/script/color.php

Code: Select all

-alpha set -channel rgba -fill "graya(0,0.25)" -colorize 100

So if you want transparent black, then you must adjust the alpha channel after creating black.

Code: Select all

-fill "black" -colorize 100 -alpha set -channel a -evaluate set 25% +channel
Double the % to %% if in a .bat file

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

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

See changes above
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Thanks Fred. The last snippet you provided works, but it does not account for transparent hole in the image. I am working with a image similar to a picture frame, with border all around edges and inside is transparent. The result I get is perfect except it fills in the hole in the image. Im not sure if that means I need to take a different approach.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Just got it to work. Here is what I worked:

-fill "black" -colorize 100 -evaluate set 25%% +channel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

That is not correct if you want transparency. It is making a 25% gray image with no transparency. It is the same as just

Code: Select all

-fill "gray(25%%)" -colorize 100
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Your right. I took a closer look at the image. It fix the issue with the hole in the image, but as you said there is actually no transparency.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

Perhaps you should provide your full command line and explain if you want transparency or not.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Here is the image I am working with: https://drive.google.com/file/d/1hbqP8e ... sp=sharing
The black part of the image is transparent.

The is the full command I am using: -fill "black" -colorize 100 -alpha set -channel a -evaluate set 60%% +channel

and here is result:
https://drive.google.com/file/d/1-7rJj9 ... sp=sharing
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by snibgo »

You haven't said what you are trying to do. You have an image, with an opaque picture frame, surrounding a transparent rectangle. Do you want to change the transparent pixels, or all pixels, or what?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

You have not give the full command line starting with convert showing your input and output images. So we really do not know what you are trying to do nor why?
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

convert frame.tiff -fill "black" -colorize 100 -alpha set -channel a -evaluate set 60%% +channel frame2.tiff

I am trying to get the frame/border in frame.tiff filled black with about 60% transparency. The above code works except, it also fills in the inner part of the frame and that I dont want.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

If you provide your input image, we can probably help more. Does the input have transparency? Can you create a binary mask that corresponds to just the border that you want to add transparency?
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by josephs »

Input image: https://drive.google.com/file/d/1hbqP8e ... sp=sharing
Output image: https://drive.google.com/file/d/1-7rJj9 ... sp=sharing

Yes, the input has transparency only inside of the frame. I can create a mask. I will work in that direction.

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

Re: Windows equivalent of: -fill "black(25%)" -colorize 100

Post by fmw42 »

The interior of your frame.tif is already transparent. So I am not sure what you want to do. What do you expect to happen in the middle?

If you want to change the border transparency and keep the center fully transparent, then just multiply the alpha channel of the image by 0.6.

Code: Select all

convert frame.tif -channel a -evaluate multiply 0.6 +channel result.tif
Post Reply