Just need a little help with the stack I think

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
jonfhancock
Posts: 3
Joined: 2011-02-18T10:08:13-07:00
Authentication code: 8675308

Just need a little help with the stack I think

Post by jonfhancock »

OK, I have two images to work with in the beginning, and I have three successful commands to get me to the finished result. I am trying to combine the commands down to one and avoid temporary images.

The starting images are:
android.png
Image

and concentric.png
Image

The first command uses the android as an alpha channel mask so I end up with an android cutout of concentric.png including the drop shadow

Code: Select all

convert concentric.png android.png -alpha Set -compose Dst_In -composite android-con.png
The result is android-con.png
Image

But it is a little too transparent, so the next command just doubles it up

Code: Select all

convert android-con.png \( +clone \) -composite android-dub.png
Which yields android-dub.png
Image

But, I want to bring in a white glow in place of the blue drop shadow to help define the lines a little better, so I run:

Code: Select all

convert android.png -negate android-con.png -composite android-final.png
Which yields the final result android-final.png
Image


Now for combining them:

I started with bringing it down to two commands:

Code: Select all

convert concentric.png android.png -alpha Set -compose Dst_In -composite android-con.png

convert android.png -negate \( android-con.png \( +clone \) -composite \) -composite android-final.png
Which works great. But, when I try to replace "android-con.png" with the first command, the image comes out wrong.

Code: Select all

convert android.png -negate \( \( concentric.png android.png -alpha Set -compose Dst_In -composite \) \( +clone \) -composite \) -composite android-fail.png
Yields android-fail.png
Image

I'm sure I'm misunderstanding either the way parentheses work, or the way +clone works. Any advice?

Thanks,

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

Re: Just need a little help with the stack I think

Post by fmw42 »

try adding -respect-parenthesis at the beginning after convert in case -negate is creaping into the parenthese. Just a guess.

and/or

replace

android.png -negate

with

\( android.png -negate \)
jonfhancock
Posts: 3
Joined: 2011-02-18T10:08:13-07:00
Authentication code: 8675308

Re: Just need a little help with the stack I think

Post by jonfhancock »

That actually gets me pretty close. This command:

Code: Select all

convert -respect-parenthesis android.png -negate \( \( concentric.png android.png -alpha Set -compose Dst_In -composite \) \( +clone \) -composite \) -composite android-fail.png
Yields:
android-fail2.png
Image

Which is just a little darker than android-final.png
Image


It sort of looks like the order is wonky, or the way it is composited is not quite right. I've tried reordering things, taking out parenthesis, and adding parenthesis, but can't seem to get any better result. Hmm
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Just need a little help with the stack I think

Post by anthony »

fmw42 wrote:try adding -respect-parenthesis at the beginning after convert in case -negate is creaping into the parenthese. Just a guess.
-negate is an operator, it is applied, not remembered.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Just need a little help with the stack I think

Post by anthony »

The very dirst command shoudl have done teh job...

Code: Select all

convert concentric.png android.png -alpha Set -compose Dst_In -composite android-con.png
The problem is that you are removing most of the darker parts of the concentric image, as they fall outside the android shape, and as such the whole image looks so much lighter than it really is.

I would suggest take the result of the above and just 'darken' it a little more using -level, sigmoidal-conrast, or -module.
That later can adjust both luminance and saturation to get the result you want.

Question are you sure your androis shape isn't semi-transparent! That would also be the cause of your problems!!
In which case do a level adjustment of just the alpha channel and fix its transparency!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
jonfhancock
Posts: 3
Joined: 2011-02-18T10:08:13-07:00
Authentication code: 8675308

Re: Just need a little help with the stack I think

Post by jonfhancock »

Thanks, anthony!

The android is semi-transparent. I've been reading through the imagemagick documentation, but I can't seem to grok how to adjust only the alpha channel. Do you have an example handy?

Thanks,

Jon
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Just need a little help with the stack I think

Post by Drarakel »

If you still wonder why the combining of your original commands wasn't completely successful: As you first use a special compositing method, you have to change it back to the default ("-compose src-over") right before the second composite. Personally, I would also avoid nested parentheses as long as possible (though that was not the reason for the differing results).

So, an equivalent for your two commands..
jonfhancock wrote:I started with bringing it down to two commands:

Code: Select all

convert concentric.png android.png -alpha Set -compose Dst_In -composite android-con.png

convert android.png -negate \( android-con.png \( +clone \) -composite \) -composite android-final.png
..would be that:

Code: Select all

convert concentric.png android.png -alpha Set -compose Dst_In -composite -compose src-over +clone -composite ( android.png -negate ) +swap -composite android-final2.png
Post Reply