Page 1 of 1

Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T14:49:06-07:00
by alexl
Hi, all.

Actually there are only 2 of images. So the original task in photoshop terms looks like:
1. open image (layer 0)
2. paste another image (layer 1), i.e. logo
3. set "layer 1" blending mode to Lighten
4. set "layer 1" opacity to 40%

My idea on how to do the same in IM is
1. compose img0 and img1 in the way like (i.e. steps 1-3 above)
composite.exe img1.png -gravity southeast -geometry +20+15 -compose lighten img0.jpg tmpresult.jpg

2. Here I need to apply the step (4). One way is to do something like this:
composite.exe tmpresult.jpg -dissolve 40% img0.jpg theresult.jpg

3. Delete temporary file:
del tmpresult.jpg

Which is not really good. Here we need to create a temporary file + extra jpeg resave operation.

So, the question is: Is there any way to do the same using just 1 command (without creating a temporary file) ?

Just read several manual pages and didn't find any solution.

Re: Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T16:11:42-07:00
by fmw42
see parenthesis and clone processing to get it into one step.

see

http://www.imagemagick.org/Usage/basics/#image_seq
http://www.imagemagick.org/Usage/basics/#clone


NOTE: composite syntax has images after the arguments.
composite argument overlayimage backgroundimage outputimage

you can use convert syntax also but input images come first and are in reverse order
convert backgroundimage overlayimage -compose lighten -composite

but -blend must done using composite rather than convert

see http://www.imagemagick.org/Usage/compose/

Have not studied your processing - just commenting on syntax and how to do in one step

Re: Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T16:15:56-07:00
by el_supremo
Try something like this:

Code: Select all

composite img1.jpg -gravity SouthEast img0.jpg -blend 40 theresult.jpg

Pete

Re: Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T16:48:53-07:00
by anthony
At this time neither of the composite operators -dissolve or -blend are available in "convert". However the two operators are relatively simple. make each image semi-transparent by multiplying their alpha channels by the appropriate value, then composite using 'over' for a -dissolve and 'plus' for a -blend.

For example... this 40% blend

Code: Select all

composite src.jpg  dest.jpg -blend 40 result.jpg
is equivalent to...

Code: Select all

convert -depth 16 \
        \( dest.jpg -matte -channel A -evaluate multiply .6 +channel \) \
        \( src.jpg -matte -channel A -evaluate multiply .4 +channel \) \
        -compose plus -composite   result.jpg
The -depth ensures we get a more accurate result in the images.

Yes these operators should really be made available in "convert". Possibly with the ability to take a longer list of 'alpha channel multipliers' to allow combining more than two images at a time. (What should it do if the number of modifiers does not match the number of images given?)

For a equal 50/50 blend, see -average

Re: Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T17:35:08-07:00
by alexl
Thanks, all!

So, now it looks like:

Code: Select all

convert -depth 16 ( img0.jpg -matte -channel A -evaluate multiply .6 +channel ) ( ( -compose lighten -composite img1.png img0.jpg ) -matte -channel A -evaluate multiply .4 +channel ) -compose plus -composite result.jpg
Or, finally, with gravity/geometry:

Code: Select all

convert -depth 16 ( img0.jpg -matte -channel A -evaluate multiply .6 +channel ) ( ( -compose lighten -composite -gravity southeast -geometry +20+15 img0.jpg img1.png ) -matte -channel A -evaluate multiply .4 +channel +geometry ) -compose plus -composite result.jpg
One more thing. Is there way to calculate the 0.6 value automatically based on 0.4 value ?
For example, if I need to bring out the 0.4 as a parameter to commandline.

Re: Composing of 3 images (or yet another watermarking)

Posted: 2008-06-12T17:50:36-07:00
by fmw42
One way,

fact1=0.6
fact2=`convert xc: -format "%[fx:1-$fact1]" info:`

Then put $fact1 and $fact2 in your command line in place of 0.6 and 0.4

see fx escapes http://www.imagemagick.org/Usage/transform/#fx_escapes