Reputation: 13
I am trying to put a label with a transparent background on an image, which works, but there is an issue with padding. The text is too close to the top of the transparent background. I wanted to add some padding to it, but I can't seem to get it to work. I know I could probably do it with draw for the background instead, but the length of the label changes all the time. I guess I could estimate the size I need based on character length, but is there a more simple way in image magick?
I tried to search for an option to maybe change line height or something, but just found spacing between words, chars, or lines instead.
Any ideas?
Convert input.jpg -fill white -undercolor 'rgba(0, 0, 0, .75)' -font Helvetica -pointsize 48 -gravity south -annotate +0+35 " Blah blah blah " output.jpg
Upvotes: 1
Views: 2334
Reputation: 465
This can also be a solution for adding a padding on all sides of a transparent text image
Use:
-gravity southeast -splice 20x20 -gravity northwest -splice 20x20
This solution works good for me
Without Padding:
convert -background "rgba(0, 255 ,0, 0.7)" \
-font "Lobster-Regular.ttf" -pointsize "60" \
-fill "#FFFFFF" label:"PROMOTE ANYTHING" \
heading.png
With Padding:
convert -background "rgba(0, 255 ,0, 0.7)" \
-font "Lobster-Regular.ttf" -pointsize "60" \
-fill "#FFFFFF" label:"PROMOTE ANYTHING" \
-gravity southeast -splice 20x20 -gravity northwest -splice 20x20 \
heading.png
Upvotes: 1
Reputation: 207345
You could use label
to create your label, then splice
some extra lines on top, then composite that onto your image. It is a bit ugly but not too complicated.
convert -background 'rgba(0, 0, 0, .75)' \
-fill white -font Helvetica -pointsize 48 \
label:" Blah blah blah " -splice 0x10 \
input.jpg \
+swap -gravity south \
-geometry +0+10 -composite result.jpg
Or you can do it the other way around and preserve the metadata:
convert input.jpg \
\( -background 'rgba(0, 0, 0, .75)' -fill white \
-font Helvetica -pointsize 48 \
label:" Blah blah blah " -splice 0x10 \
\) -gravity south -geometry +0+10 -composite result.jpg
Upvotes: 4