Page 1 of 1

Layering Images with convert -composite with gravity center

Posted: 2012-01-27T04:12:30-07:00
by tomasikp
Image
background
Image
overlay

Code: Select all

composite -gravity center overlay.png  background.jpg  result1.jpg
Image
result1.jpg

Code: Select all

convert -composite background.jpg overlay.png -gravity center result2.jpg
Image
result2.jpg

Code: Select all

convert -composite background.jpg -gravity center tool_marker.png  result3.jpg
Image
result3.jpg


How can I achieve the results from result1 while using convert as the executable rather than composite?

Thanks!

Re: Layering Images with convert -composite with gravity cen

Posted: 2012-01-27T04:39:28-07:00
by anthony
You can start by using the operators in the right order. That is set the 'settings' first.
"Composite" command is 'read all settings then apply ONE operation, type of command (traditional UNIX)
"Convert" is a 'do options as you see them', with MULTIPLE operations possible. (script-like command)

Code: Select all

convert  background.jpg  tool_marker.png -geometry +50+50 -composite result4.jpg
Note the +50+50 is the location of the top-left corner of the 'tool_marker.png" image. You will need to subtract the 'pin-point' location in that image to get it to pin point in the right location.

Gravity Center (if given BEFORE the -composite operation that uses it), aligns the center of BOTH images.

In IMv7 I have a 'justification' setting planned. That will position the image using gravity, then the overlay image using justification relative to that position, BUT it will not position the image to a specific point!

Hmmm that may not be a bad idea as a way to implement justification, and now is the time for such ideas. I will need to think about it.

Eg: -geometry and -gravity locates the position on the background image, while -justification locates the point in the overlay image that is to be aligned with that location! (all will need to be integers, as only image distortions can do sub-pixel positioning of images).

Re: Layering Images with convert -composite with gravity cen

Posted: 2012-01-27T05:08:41-07:00
by tomasikp
thank you for the quick reply Anthony. Sorry about not using the operators in the right order. Justification sounds like a great setting!

Re: Layering Images with convert -composite with gravity cen

Posted: 2012-01-27T17:04:27-07:00
by anthony
It will be in IMv7 but that is still in development. Mean time the best way is to forget gravity, and just set geometry equal to location for pin minus location pf pin-point in the overlay image.

For example hmmm... Th pin-point on overlay image is +18+41 from the top left corner.
so to put at pin at.... "Accademia" which is at +160+283
you subtract and get a composition offset of +142+242

Code: Select all

convert venice.jpg pin.png -geometry +142+242 -composite venice_pinned.jpg
Image

If you are putting in lots of pins, a better way is to 'layer' the images. This uses a '-page' or virtual image offsets to place overlay images... See
http://www.imagemagick.org/Usage/layers/#flatten
For example...

Code: Select all

convert venice.jpg \
            \( pin.png -repage +142+242 \) \
            \( +clone -repage +236+125 -modulate 100,100,33.3  \) \
            \( +clone -repage +280+184 -modulate 100,100,133.3  \) \
            -flatten  venice_landmarks.jpg
Image

To avoid reading in multiple colored 'pins' I clone the existing pint, re-position it, then recolor using 'modulate' to rotate the non-gray colors. For details see Color Modifications, Modulate
http://www.imagemagick.org/Usage/color_mods/#modulate

Also see the Basic's section, about command line order, settings, operators, etc...
http://www.imagemagick.org/Usage/basics/

Re: Layering Images with convert -composite with gravity cen

Posted: 2012-01-27T18:45:48-07:00
by fmw42
I don't know if this makes the computation easier, but if you fill out your pin image with transparency so that the pin point is at the center, then you can use -gravity center -geometry ... But then you have to measure the offsets for -geometry relative to the center of the background image.

However, if you have lots of pins to place, using -page -flatten is likely going to be easier and perhaps faster in the long run.

Re: Layering Images with convert -composite with gravity cen

Posted: 2012-01-27T20:13:40-07:00
by anthony
Added the above as well as an expanded 'data file to pins' example into IM Examples...
http://www.imagemagick.org/Usage/layers/#layer_pins

This would make a great example where the map is 'layed flat' and pins added in a sort of 3-D view.