Inconsistency with text metrics IM 6.8.9-9
Posted: 2016-10-31T06:24:13-07:00
IM version:
ImageMagick 6.8.9-9 Q16 x86_64 2016-05-16
Debian 8.4 - x64
Issue
I've recently tried to get the size of a given text in pixel but found myself puzzled by an inconsistency.
The following script retrieves the sizes of each word passed as a variable and output a total size.
Here is the output:
Now, it's time to get the size of all these words already concatenated together, without any space between them:
Output:
As you can see, there is a difference of 7~ pixels. It's really problematic when you want to know exactly which size a text will be in pixel. I used to do some auto-fit with caption but with a specific pointsize and that kind of inconsistency doesn't allow to forecast when a new line will occur or if a text will fit correctly in a box.
ImageMagick 6.8.9-9 Q16 x86_64 2016-05-16
Debian 8.4 - x64
Issue
I've recently tried to get the size of a given text in pixel but found myself puzzled by an inconsistency.
The following script retrieves the sizes of each word passed as a variable and output a total size.
Code: Select all
text="Test de la saucisse seche ij."
IFS=', ' read -r -a array <<< "$text" # Put each word in a list
array_lengh=$(echo ${#array[@]})
total_size=0
i=0
for element in "${array[@]}"
do
i=$(echo $(($i + 1)))
size=$(convert -debug annotate xc: -font /home/server/streams/_thumbnails/_resources/BebasNeue.otf -pointsize 130 -interword-spacing 20 -kerning 0 -annotate 0 "$element" null: 2>&1 | grep "Metrics:" | awk -F ";" '{print $2}' | awk -F ": " '{print $2}')
echo "($i) $element=$size"
total_size=$(echo "$total_size+$size" | bc)
done
echo $total_size
(1) Test=188.953
(2) de=96.7969
(3) la=96.5625
(4) saucisse=374.562
(5) seche=249.016
(6) ij.=81.7031
user@server:~/scripts$ echo $total_size
1087.5935
Now, it's time to get the size of all these words already concatenated together, without any space between them:
Code: Select all
convert -debug annotate xc: -font /home/server/streams/_thumbnails/_resources/BebasNeue.otf -pointsize 130 -interword-spacing 20 -kerning 0 -annotate 0 "Testdelasaucissesecheij." null: 2>&1 | grep "Metrics:" | awk -F ";" '{print $2}' | awk -F ": " '{print $2}'
1094.95
As you can see, there is a difference of 7~ pixels. It's really problematic when you want to know exactly which size a text will be in pixel. I used to do some auto-fit with caption but with a specific pointsize and that kind of inconsistency doesn't allow to forecast when a new line will occur or if a text will fit correctly in a box.