Page 1 of 2

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

Posted: 2018-02-17T19:31:09-07:00
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.

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

Posted: 2018-02-17T19:41:05-07:00
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.

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

Posted: 2018-02-17T20:27:31-07:00
by fmw42
See changes above

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

Posted: 2018-02-17T21:00:15-07:00
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.

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

Posted: 2018-02-17T21:04:46-07:00
by josephs
Just got it to work. Here is what I worked:

-fill "black" -colorize 100 -evaluate set 25%% +channel

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

Posted: 2018-02-17T21:12:45-07:00
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

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

Posted: 2018-02-17T21:15:57-07:00
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.

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

Posted: 2018-02-17T21:17:01-07:00
by fmw42
Perhaps you should provide your full command line and explain if you want transparency or not.

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

Posted: 2018-02-17T21:30:54-07:00
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

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

Posted: 2018-02-17T22:02:00-07:00
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?

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

Posted: 2018-02-17T22:13:27-07:00
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?

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

Posted: 2018-02-17T22:27:24-07:00
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.

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

Posted: 2018-02-17T22:39:53-07:00
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?

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

Posted: 2018-02-17T22:43:50-07:00
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.

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

Posted: 2018-02-17T22:49:25-07:00
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