fwarren

ImageMagik text width

Feb 8th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.69 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # sample output for fred warren 0 96
  4. #
  5. # 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;
  6. #    underline position: -4.5625; underline thickness: 2.34375
  7. #
  8. # Expects Name to be 2 words and will find the correct font and kerning with a max of 96px 12.9 kerning
  9. # Will fit in 720px wide
  10.  
  11. # Start at 96px and work down to 60px / stop when width is under 702
  12. name="Johnny Doe"
  13. px=97
  14. width=999
  15. max=702
  16. while [[ $width -gt $max ]]
  17. do
  18.   ((px = px - 1 ))
  19.   output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning 0  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  20.   width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  21.   height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
  22. done
  23.  
  24. # Start at 12.0 kerning down to 0.0 kerning / stop when width is under 702 / steps 12 to 0
  25. kern=13
  26. width=999
  27. while [[ $width -gt $max ]]
  28. do
  29.   ((kern = kern - 1 ))
  30.   output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning $kern  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  31.   width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  32.   height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
  33. done
  34.  
  35.  
  36.  
  37. # Starting at $KERING.9 to $KERING.0 / stop when width is under 702 / steps 9 to 0
  38. krn=10
  39. width=999
  40. while [[ $width -gt $max ]]
  41. do
  42.   ((krn = krn - 1 ))
  43.   output=`convert -debug annotate  xc: -font .fonts/alpha_echo.ttf  -pointsize $px -kerning $kern.$krn  -annotate 0 "$name" null: 2>&1 | grep Metrics:`
  44.   width=`echo $output|cut -d " " -f6,8|cut -d ";" -f1`
  45.   height=`echo $output|cut -d " " -f6,8|cut -d ";" -f2`
  46. done
Advertisement
Add Comment
Please, Sign In to add comment