fwarren icon

ImageMagik text width

fwarren | PRO | 02/08/17 10:31:37 PM UTC | 0 ⭐ | 329 👁️ | Never ⏰ | []
Bash |

1.69 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
# sample output for fred warren 0 96
#
# Metrics: text: fred warren; width: 483; height: 110; ascent: 87; descent: -20; max advance: 192; bounds: 0,-1 68.5781,69.75; origin: 484,0; pixels per em: 96,96; 
#    underline position: -4.5625; underline thickness: 2.34375
#
# Expects Name to be 2 words and will find the correct font and kerning with a max of 96px 12.9 kerning
# Will fit in 720px wide
 
# Start at 96px and work down to 60px / stop when width is under 702
name="Johnny Doe"
px=97
width=999
max=702
while [[ $width -gt $max ]]
do
  ((px = px - 1 ))
  output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning 0  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
done
 
# Start at 12.0 kerning down to 0.0 kerning / stop when width is under 702 / steps 12 to 0
kern=13
width=999
while [[ $width -gt $max ]]
do
  ((kern = kern - 1 ))
  output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning $kern  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
done
 
 
 
# Starting at $KERING.9 to $KERING.0 / stop when width is under 702 / steps 9 to 0 
krn=10
width=999
while [[ $width -gt $max ]]
do
  ((krn = krn - 1 ))
  output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning $kern.$krn  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
done

Comments