Reputation: 27667
how can you change the width of an image depending on the width of the text?
if you want a 5 pixel padding both to the left and right of the text?
and how can you define the path to the font you want to use?
Upvotes: 0
Views: 634
Reputation: 90203
'How to change width of image depending on width of text?'
You can use a really biiiig drawing canvas first and then -trim
to trim the superfluous space around your text. For example:
convert \
-font "Courier" \
-size 800x200 \
xc:none \
-box green \
-pointsize 24 \
-gravity center \
-draw "text 0,0 'This is clarkk\'s text...'" \
-trim \
clarkk.jpeg
'How to add 5 pixels padding to both left and right of the text?'
You can use any of the different ImageMagick methods to add left and right pixels to the resulting image from step 1. For example:
convert \
clarkk.jpeg \
-gravity center \
-extent $(identify -format '%[fx:W+10]x%H' clarkk.jpeg) \
clarkk-padded.jpeg
'How to define the path of the font I want to use?'
You can use the -font "/path/to/some directory with/fontname.ttf"
directive.
convert \
-font "/Library/Fonts/Verdana Italic.ttf" \
-size 800x200 \
xc:none \
-box green \
-pointsize 24 \
-gravity center \
-draw "text 0,0 'This is clarkk\'s text...'" \
-trim \
clarkk-font.jpeg
To get a list of fonts which are accessible to ImageMagick, run
convert -list font
Upvotes: 1