get Font Size in Python with Tesseract and Pyocr
<p>Is it possible to get font size from an image using <code>pyocr</code> or <code>Tesseract</code>?
Below is my code.</p>

<pre><code>tools = pyocr.get_available_tools()
tool = tools[0]
txt = tool.image_to_string(
      Imagee.open(io.BytesIO(req_image)),
      lang=lang,
      builder=pyocr.builders.TextBuilder()
)
</code></pre>

<p>Here i get text from image using function <code>image_to_string</code> . And now, my question is, if i can get <code>font-size</code>(number) too of my text.</p>

<p>Using <a href="https://github.com/sirfz/tesserocr" rel="nofollow">tesserocr</a>, you can get a <code>ResultIterator</code> after calling <code>Recognize</code> on your image, for which you can call the <code>WordFontAttributes</code> method to get the information you need. Read the method's documentation for more info.</p>

<pre><code>import io
import tesserocr
from PIL import Image

with tesserocr.PyTessBaseAPI() as api:
    image = Image.open(io.BytesIO(req_image))
    api.SetImage(image)
    api.Recognize()  # required to get result from the next line
    iterator = api.GetIterator()
    print iterator.WordFontAttributes()
</code></pre>

<p>Example output:</p>

<pre><code>{'bold': False,
 'font_id': 283,
 'font_name': u'Times_New_Roman',
 'italic': False,
 'monospace': False,
 'pointsize': 9,
 'serif': True,
 'smallcaps': False,
 'underlined': False}
</code></pre>

python tesseract font-size python-tesseract