4

I need to add borders around photos and below the photo I want to append text. However, so far I can either add borders or add text, but they don't work togeter.

original photo

What I mean is, for appending text:

convert photo.jpg -background White label:"A nice memory" -background White -gravity east -append result.jpg

This adds a white strip with text at the bottom right of the image:

Photo with text

and for adding border:

convert photo.jpg -bordercolor Green -border 5%x10% result.jpg

enter image description here

It adds a nice green border around the photo. However, if I want them together:

convert photo.jpg -bordercolor Green -border 5%x10% -background White label:"A nice memory" -background White -gravity east -append result.jpg

enter image description here

it first adds a border, then an extra strip of space below the lower border with text. I guess I have to explicitly tell it to have border and text together. Is this possible?

Expected:

Expected result

(Important: I want the text to be right aligned with the photo as if there's no border)

Thanks!

fmw42
  • 46,825
  • 10
  • 62
  • 80
Heuristic
  • 5,087
  • 9
  • 54
  • 94

2 Answers2

3
convert input.jpg -bordercolor Green -border 5%x10% -gravity southeast -annotate +0+0 "Some text" result.jpg
Bonzo
  • 5,169
  • 1
  • 19
  • 27
  • Thanks! This works mostly, I'll need to figure out how to right-align the text with the photo itself, not with the border. – Heuristic Dec 30 '17 at 23:04
  • 1
    If you had a fixed border rather than a % you could adjust the +0+0 to something like -20+0 in the -annotate – Bonzo Dec 30 '17 at 23:17
0

In Imagemagick 6, you can do it as follows (unix syntax):

infile="logo:"
offx=`convert $infile -format "%[fx:5*w/100]" info:`
offy=`convert $infile -format "%[fx:2.5*w/100]" info:`
convert $infile -bordercolor Green -border 5%x10% -font Arial -pointsize 18 -gravity southeast -annotate +${offx}+${offy} "Some text" result.jpg


In Imagemagick 7, you can do it as:

magick logo: -bordercolor Green -border 5%x10% -font Arial -pointsize 18 -gravity southeast -annotate +%[fx:5*w/100]+%[fx:(10/4)*h/100] "Some text" result.jpg


The offset (1/4 value) may need to be adjusted for the pint-size so that the text will be centered vertically in the space provided.

The image, logo:, is an internal Imagemagick image which requires the colon.

fmw42
  • 46,825
  • 10
  • 62
  • 80