Stefan P
Stefan P

Reputation: 640

Positioning layers

At the moment I'm working on a quite comprehensive (well at least for me) imagemagic task. I want to add some annotations i extract from exif-data and adding an overlay image. At the moment i'm having the following code:

convert -verbose source.jpg \
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity North     -annotate +10+10 "more exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
    -gravity South overlay.png \
    -layers flatten \
    -quality 95 destination.jpg;

The annotation works fine including the position. But i stuck with the overlay. It seems the the "-gravity South" doesn't work here. It stuck on the upper left corner. What do i have to change to get the overlay to the bottom and centered?

Bonus question: How to get the overlay semitransparent?

Upvotes: 1

Views: 266

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 208052

You should use -composite rather than -flatten with your convert:

convert -verbose source.jpg \
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity North     -annotate +10+10 "more exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
    -gravity South overlay.png -composite \
    result.jpg

enter image description here

If you want the overlay semi-transparent, use:

convert -verbose source.jpg \
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity North     -annotate +10+10 "more exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
    \( -gravity South overlay.png -channel A -fx "0.5" \) -composite \
    result.jpg

By the way, -pointsize, -fill, and -undercolor are "settings", so they remain set until changed, so you don't need to repeat them:

convert -verbose source.jpg -pointsize 32 -fill white -undercolor '#00000070' \
    -gravity NorthWest -annotate +10+10 "some exif data"\
    -gravity North     -annotate +10+10 "more exif data"\
    -gravity NorthEast -annotate +10+10 "even more exif data"\
    \( -gravity South overlay.png -channel A -fx "0.5" \) -composite \
    result.jpg

Upvotes: 2

zindarod
zindarod

Reputation: 6468

You need to add overlay with composite not convert.

convert -verbose source.jpg \
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity North     -annotate +10+10 "more exif data"\
    -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
    -layers flatten \
    -quality 95 destination.jpg;

and then:

composite -gravity South overlay.png destination.jpg result.jpg

More on composite here.

Edit: Best way would be to use ImageMagick intermediate save format miff and pipelining. This will save extra steps of read/write from disk.

convert -verbose source.jpg \
        -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthWest -annotate +10+10 "some exif data"\
        -pointsize 32 -fill white -undercolor '#00000070' -gravity North     -annotate +10+10 "more exif data"\
        -pointsize 32 -fill white -undercolor '#00000070' -gravity NorthEast -annotate +10+10 "even more exif data"\
        -layers flatten \
        -quality 95 miff:- | \

composite -gravity South overlay.png miff:- destination.jpg

Upvotes: 1

Related Questions