Need help making old -mask command work with 7.?

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?".
Post Reply
User avatar
dshimer
Posts: 3
Joined: 2017-11-15T07:25:40-07:00
Authentication code: 1152
Location: Central Ohio, USA

Need help making old -mask command work with 7.?

Post by dshimer »

I have a mask which is a black to white gradient. Previously if I ran

Code: Select all

convert in.tif -mask mask.tif -level 30%,100%,.7 out.tif
I would get an output image which had out.tif modified in such a way that black parts of the mask were 100% changed, white 0% changed, and various shades of grey were modified in a smooth gradient of whatever effect. I tried the same thing on a machine with 7.0.7-11 installed and the same exact command yields a file that has a hard edged mask which looks like a pure black and white mask with the transition being somewhere near a midpoint threshold of the grey values.
Though I couldn't really come across a good explanation of why I thought I would try the -read-mask option and the magick command but that didn't help either. So I would love a pointer into how to accomplish what I need or where some examples or full documentation regarding how to apply a gradient mask can be found.
Information freely given away is often returned with interest.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Need help making old -mask command work with 7.?

Post by GeeMack »

dshimer wrote: 2017-11-15T07:45:56-07:00I tried the same thing on a machine with 7.0.7-11 installed and the same exact command yields a file that has a hard edged mask which looks like a pure black and white mask with the transition being somewhere near a midpoint threshold of the grey values.
I've encountered the same issue using an input image, a gradient mask the same size as the input, and a command like this...

Code: Select all

magick in.tif -write-mask mask.tif -level 30%,100%,0.7 +write-mask out.tif
The output has a hard edge division about half way down, with the modified image above and the original input below. It does seem to be incorrect behavior, but maybe I'm also misunderstanding how "-write-mask" is supposed to work.

Using IM 7.0.7-11 I can get the correct result you describe with a command like this...

Code: Select all

magick in.tif ( -clone 0 -level 30%,100%,0.7 ) mask.tif -composite out.tif
That reads the input image, modifies a clone of it inside the parentheses, reads the gradient mask image, then composites the modified clone over the original input using the mask to create the graduated effect.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help making old -mask command work with 7.?

Post by snibgo »

The documentation for "-write-mask" http://www.imagemagick.org/script/comma ... write-mask says:
This the same as using a mask used for composite masking operations, with grayscale values causing blended updates of the image the mask is attached to.
It isn't supposed to be boolean.

It should be used with "+write-mask".

The porting guide http://www.imagemagick.org/script/porting.php says it should be used with "+mask", but that's wrong. ("+mask" raises an error.)
snibgo's IM pages: im.snibgo.com
User avatar
dshimer
Posts: 3
Joined: 2017-11-15T07:25:40-07:00
Authentication code: 1152
Location: Central Ohio, USA

Re: Need help making old -mask command work with 7.?

Post by dshimer »

@GeeMack Perfect. Thanks!
GeeMack wrote: 2017-11-15T08:37:46-07:00
Using IM 7.0.7-11 I can get the correct result you describe with a command like this...

Code: Select all

magick in.tif ( -clone 0 -level 30%,100%,0.7 ) mask.tif -composite out.tif
That reads the input image, modifies a clone of it inside the parentheses, reads the gradient mask image, then composites the modified clone over the original input using the mask to create the graduated effect.
Last edited by dshimer on 2017-11-15T09:26:45-07:00, edited 1 time in total.
Information freely given away is often returned with interest.
User avatar
dshimer
Posts: 3
Joined: 2017-11-15T07:25:40-07:00
Authentication code: 1152
Location: Central Ohio, USA

Re: Need help making old -mask command work with 7.?

Post by dshimer »

I tried a couple dozen variations of information I found there but just couldn't get anything to work as a gradient. I appreciate the reminder to go read it again word for word because I picked up on the fact that
This polarity is the reverse of masks in version 6 of ImageMagick.
snibgo wrote: 2017-11-15T08:52:45-07:00 The documentation for "-write-mask" http://www.imagemagick.org/script/comma ... write-mask says:
Information freely given away is often returned with interest.
Post Reply