Page 1 of 1

convert's result - merge with original

Posted: 2015-05-15T03:51:34-07:00
by TiborB
Hi,

I am doing this:

Code: Select all

convert input.jpg -channel all -normalize -output.jpg
and I need to limit the effect to f.e. 50%. Effectively like set the result on top layer and set the opacity of it to 50%. (In gimp it is trivial for me)

I read about all that compose, composite, dissolve, clone and everything but I am quite confused, so if somebody was so kind and write me that command...

Thanks

Re: convert's result - merge with original

Posted: 2015-05-15T09:37:12-07:00
by fmw42
JPG does not support transparency. You need to save your output to PNG or TIFF.

NOTE: the output image should not start with -output.jpg

Try this

Code: Select all

convert input.jpg  -normalize -alpha set -channel a -evaluate set 50% +channel output.png
see
http://www.imagemagick.org/Usage/masking/#alpha_set

-alpha set simple enables an alpha channel
-channel a selects only the alpha channel
-evaluate set 50% makes the alpha channel 50% transparent
+channel turns on all the channels r,g,b,a

Re: convert's result - merge with original

Posted: 2015-05-15T10:59:42-07:00
by snibgo
I think the OP wants something different. Windows BAT syntax:

Code: Select all

%IM%convert ^
  in.jpg ^
  ( +clone ^
    -normalize ) ^
  -compose Blend -define compose:args=50 -composite ^
  out.jpg
This makes a copy of the input, and applies an effect to that copy. The effect is a simple "-normalize", but could be more complex. Then it blends this with the original input.

EDIT: Removed superfluous caret ^.

Re: convert's result - merge with original

Posted: 2015-05-15T12:37:26-07:00
by TiborB
Thanks guys,

Snibgo's answer is exactly what I asked for. Thank you very much.
Also, I can say the syntax is completely unintuitive :)

Re: convert's result - merge with original

Posted: 2015-05-15T12:41:37-07:00
by fmw42
snibgo wrote:I think the OP wants something different. Windows BAT syntax:
You are probably correct. It was not clear to me what he wanted.

I just read
set the opacity of it to 50%
and thought he just wanted 50% transparency.

Since the user did not specify his version of IM nor platform, note that snibgo's syntax is for Windows and for Unix it needs some changes.

Code: Select all

convert \
  in.jpg \
  \( +clone \
    -normalize \) \ 
  -compose Blend -define compose:args=50 -composite \
  out.jpg

Re: convert's result - merge with original

Posted: 2015-05-15T12:44:15-07:00
by fmw42
I believe there is an extra ^ after -normalize and before the ) ^. I do not think that will cause a problem. It just adds a newline an extra newline.

Re: convert's result - merge with original

Posted: 2015-05-15T12:48:07-07:00
by fmw42
TiborB wrote: Also, I can say the syntax is completely unintuitive :)
snibgo wrote:%IM%convert ^
in.jpg ^
( +clone ^
-normalize ^ ) ^
-compose Blend -define compose:args=50 -composite ^
out.jpg
The ( ... ) clones, ie copies the input and applies -normalize. Then the input and the copied and process images are blended with a 50% (equal) weighting.

I believe you can also approach this by doing the clone and -normalize and then adding a 50% transparent alpha channel similar to what I had above. Then flattening the input and processed images together rather than blending. I believe that this is more like what GIMP and PS do.

Re: convert's result - merge with original

Posted: 2015-05-15T14:30:32-07:00
by snibgo
fmw42 wrote:I believe there is an extra ^ ...
So there is, thanks. I have edited it. (I mean to hit newline after the first caret, to put the end-parenthesis on a new line, but didn't.)

As Fred says, there are a number of ways of doing this task. I think "-compose Blend" is as quick as they get.

IM is very powerful, and the syntax isn't intuitive until you learn the semantics.

In this example, the parentheses ( and ) makes the "-normalize" operation apply to just the clone, not to both the clone and the input image.

Code: Select all

-compose Blend -define compose:args=50 -composite
This applies the "-composite" operation, which takes two input images and makes one output.

The setting "-compose Blend" controls the type of composition used. An infinite number of blends are possible, so we also need to say how much we want. I can never remember the syntax of "-define compose:args=50" and had to look it up.

Keywords could be added to IM to simplify syntax, eg "-blend 50" could be a synonym of "-compose Blend -define compose:args=50 -composite".

This would add hundreds or thousands of entries to the dictionary, so I'm not sure if it would help the learning process.