combining chained convert commands into one

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
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

combining chained convert commands into one

Post by sas »

I'm trying to darken and blur a grayscale PNG image, and then replace all pixels which are darker than gray2, with gray2.

This works fine:

Code: Select all

convert a.png  -level 0%,85%  -blur 0x5   b.png
convert b.png  -black-threshold '2%'      c.png
convert c.png  -fill gray2 -opaque black  d.png
However if I try to combine them all into one command to avoid creating the intermediate images b.png and c.png, it doesn't have the same result:

Code: Select all

convert a.png  -level 0%,85%  -blur 0x5 \
               -black-threshold '2%' \
               -fill gray2 -opaque black  d.png
What am I missing?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: combining chained convert commands into one

Post by fmw42 »

Your two commands should work the same. What version of IM, libpng and what platform are you using? Post an example of a.png and your two d.png results to some place such as dropbox.com and then put the URLs here.

You could add a little -fuzz XX% in case some values are not quite at gray2. But in principle, you commands should work.

Your command -level 0x85% is going to brighten the image, not darken it.
sas
Posts: 44
Joined: 2009-11-28T16:35:46-07:00
Authentication code: 8675309

Re: combining chained convert commands into one

Post by sas »

Huh, you're right, it does work.

No idea what I did wrong when I tried it yesterday... :oops:

Thanks for responding!
fmw42 wrote:You could add a little -fuzz XX% in case some values are not quite at gray2. But in principle, you commands should work.
I'm not replacing gray2 pixels, I'm replacing a range of pixel values to gray2.

(Maybe I chose a strange way to do it?)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: combining chained convert commands into one

Post by fmw42 »

try

Code: Select all

convert a.png -level 0%,85%  -blur 0x5 -evaluate max 2% d.png
Post Reply