convert's result - merge with original

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
TiborB
Posts: 5
Joined: 2015-05-15T03:40:08-07:00
Authentication code: 6789

convert's result - merge with original

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's result - merge with original

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert's result - merge with original

Post 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 ^.
snibgo's IM pages: im.snibgo.com
TiborB
Posts: 5
Joined: 2015-05-15T03:40:08-07:00
Authentication code: 6789

Re: convert's result - merge with original

Post 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 :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's result - merge with original

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's result - merge with original

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert's result - merge with original

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert's result - merge with original

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply