title: Measuring width of text (Python/PIL)
body: <p>I'm using the following two methods to calculate a sample string's rendered <strong>width</strong> for a set font-type and size:</p>
  
  <pre><code>font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 14)
  sample = "Lorem ipsum dolor sit amet, partem periculis an duo, eum lorem paulo an, mazim feugiat lobortis sea ut. In est error eirmod vituperata, prima iudicabit rationibus mel et. Paulo accumsan ad sit, et modus assueverit eum. Quod homero adversarium vel ne, mel noster dolorum te, qui ea senserit argumentum complectitur. Duo at laudem explicari deterruisset, eu quo hinc mnesarchum. Vel autem insolens atomorum at, dolorum suavitate voluptatum duo ex."
  #METHOD 1
  draw_txt = ImageDraw.Draw(img)
  width, height = draw_txt.textsize(sample, font=font)
  print width
  #METHOD 2
  width = 0
  for c in sample:
      width += font.getsize(c)[0]
  print width
  </code></pre>
  
  <p><code>METHOD 1</code> yields a width of <code>3236</code>, whereas <code>METHOD 2</code> yields <code>3270</code>. Why the discrepancy? Moreover, I've also noticed that shorter the sample text, smaller the discrepancy between these two methods.</p>
  
  <p>What's going on under the hood? And which width can be thought of as the <em>true</em> width of the rendered sentence? Lastly, is there a tweak I can do to have both methods report approximately the same widths?</p>
  
  <p><em>Note: the sample text is 445 characters long</em></p>