As the OP states, there are two parts (and probably also a third part):

  1. Use PIL to generate images from fonts.

  2. Use an image analysis toolkit, like OpenCV (which has Python bindings) to compare different shapes. There are a variety of standard techniques to compare different objects to see whether they're similar. For example, scale invariant moments work fairly well and are part of the OpenCv toolkit.

  3. Most of the standard tools in #2 are designed to look for similar but not necessarily identical shapes, but for font comparison this might not be what you want, since the differences between fonts can be based on very fine details. For fine-detail analysis, try comparing the x and y profiles of a perimeter path around the each letter, appropriately normalized, of course. (This, or a more mathematically complicated variant of it, has been used with good success in font analysis.)

Answer from tom10 on Stack Overflow
Top answer
1 of 3
5

As the OP states, there are two parts (and probably also a third part):

  1. Use PIL to generate images from fonts.

  2. Use an image analysis toolkit, like OpenCV (which has Python bindings) to compare different shapes. There are a variety of standard techniques to compare different objects to see whether they're similar. For example, scale invariant moments work fairly well and are part of the OpenCv toolkit.

  3. Most of the standard tools in #2 are designed to look for similar but not necessarily identical shapes, but for font comparison this might not be what you want, since the differences between fonts can be based on very fine details. For fine-detail analysis, try comparing the x and y profiles of a perimeter path around the each letter, appropriately normalized, of course. (This, or a more mathematically complicated variant of it, has been used with good success in font analysis.)

2 of 3
4

This question is a little old, so here goes an updated answer.

You should take a look into this paper DeepFont: Identify Your Font from An Image. Basically it's a neural network trained on tons of images. It was presented commercially in this video.

Unfortunately, there is no code available. However, there is an independent implementation available here. You'll need to train it yourself, since weights are not provided, but the code is really easy to follow. In addition to this, consider that this implementation is only for a few fonts.

There is also a link to the dataset and a repo to generate more data.

Hope it helps.

🌐
Medium
jehadmohamedz.medium.com › font-recognition-with-deep-learning-e6ad9c344048
Font Recognition with Deep Learning | by Jehad Mohamed | Medium
January 17, 2022 - Since we will be manipulating images, let’s take up PIL (Python imaging library) and create a function to read an image from a directory and resize as needed. def pil_image(img_path): pil_im =PIL.Image.open(img_path).convert('L') pil_im=pil_im.resize((105,105)) #imshow(np.asarray(pil_im)) return pil_im · We will now be breaking the entire work into 4 steps or phases. Since AdobeVFR Dataset datalink is huge in size and contains lot of font categories, the simple way around this is to create a custom dataset based upon required font patches using TextRecognitionDataGenerator github.
🌐
GitHub
github.com › imneonizer › Recognize-Text-From-Images-With-Python-And-OpenCV
GitHub - imneonizer/Recognize-Text-From-Images-With-Python-And-OpenCV: You can use this code to Train on Any Font Style of English Alphabets and Numbers, This code is so powerful when it comes to extract Text From Images. And the best part is you can train the model as per your preference.
You can use this code to Train on Any Font Style of English Alphabets and Numbers, This code is so powerful when it comes to extract Text From Images. And the best part is you can train the model as per your preference. - imneonizer/Recognize-Text-From-Images-With-Python-And-OpenCV
Starred by 10 users
Forked by 4 users
Languages   Python 100.0% | Python 100.0%
🌐
GitHub
github.com › prnvdixit › Pyfont
GitHub - prnvdixit/Pyfont: A Python command-line application to detect fonts of texts in images
A Python command-line application to detect fonts of texts in images - prnvdixit/Pyfont
Author   prnvdixit
🌐
GitHub
github.com › lkmidas › Font-Detection
GitHub - lkmidas/Font-Detection: Detect texts and their fonts on an image (school project) · GitHub
Install packages in requirements.txt to run font detection · python3 data_generator.py <font_dir> <out_dir> <image_count>
Author   lkmidas
🌐
GitHub
github.com › Python-Secret-Underground › font-detection
GitHub - Python-Secret-Underground/font-detection: A deep learning application to detect the font in image
A deep learning application to detect the font in image - Python-Secret-Underground/font-detection
Author   Python-Secret-Underground
🌐
Stack Overflow
stackoverflow.com › questions › 51570207 › detecting-font-of-text-in-image
python - detecting font of text in image - Stack Overflow
July 28, 2018 - for OCR i am using tesseract, which ... understandable. one solution is to build multiple trained data - one per few similar fonts - and then automatically use the appropriate data for each image. for this to work we need to be able ...
Find elsewhere
🌐
Python Forum
python-forum.io › thread-12395.html
Is there a way to detect the text font, size and color from an image in python?
August 22, 2018 - I've done a lot of research and i cannot find a way to detect the the text font, size and color from an image in python. Here is an example of an image: Is there a way, or a specific function? Thanks, Rita Maia
🌐
GitHub
github.com › robinreni96 › Font_Recognition-DeepFont
GitHub - robinreni96/Font_Recognition-DeepFont: Its a implementation of DeepFont : Identify Your Font from An Image using Keras · GitHub
Its a implementation of DeepFont : Identify Your Font from An Image using Keras - robinreni96/Font_Recognition-DeepFont
Author   robinreni96
🌐
Google Groups
groups.google.com › g › tesseract-ocr › c › 9FKjGZRUi-M
Python Code for tesseract font detection
Hi, How can I use tesseract into my python code directly to get the font name. I am able to get the same using below command - tesseract "timesromanitalic.png" sampleoutput --oem 0 -c tessedit_debug_fonts=1 --tessdata-dir \tessdata ... This e-mail message and/or attachments being sent from Kellton Tech is privileged, confidential, and directed to and for the use of the addressee only.
🌐
GitHub
github.com › imshubhamkapoor › Font_Recognition
GitHub - imshubhamkapoor/Font_Recognition: In this project, you'll train a convolutional neural network to classify and recognize different categories of fonts. We'll be using the dataset of 100 categories of fonts to train our model.
Adobe VFR dataset is the first large-scale, fine-grained benchmark of font text images, for the task of font recognition and retrieval. Unfortunately, it is very huge so I was unable to download it. Then, I discovered the TRDG (Text Recognition Data Generator) package created by Edouard Belval in Python. It is a synthetic data generator for text recognition. Words will be randomly chosen from a dictionary of a specific language.
Starred by 12 users
Forked by 6 users
🌐
Stack Overflow
stackoverflow.com › questions › 61853768 › how-to-detect-font-family-from-an-image-in-python
How to detect font family from an image in python? - Stack Overflow
May 17, 2020 - I am trying to identify the font family from a text image but unable to find a suitable library in python. Is there any library for identifying the type of font in python ?
🌐
GitHub
github.com › GoogleCloudPlatform › python-docs-samples › issues › 2409
Can we identify the font size or font type while detecting text from images? · Issue #2409 · GoogleCloudPlatform/python-docs-samples
September 21, 2019 - Case: We want to extract the text out of images. These images contains details about product like product name, tagline, features, benefits, price etc. We need to extract those details and then tag with the correct type.
Author   GoogleCloudPlatform
🌐
Fontdetector
fontdetector.org
Font Detector - AI Font Finder from Image Free Online
Free AI font detector and font finder from image. Upload a screenshot, logo, poster, PDF crop, or photo to answer what font is this, compare similar fonts, and improve results with clear image tips.
🌐
Lipi
lipi.ai › identify
Free Font Finder - Detect Text & Identify Fonts from Images | Lipi.ai
June 2, 2026 - Upload any image to detect text regions and identify fonts for free. Text extraction and font matching.
🌐
Font Squirrel
fontsquirrel.com › matcherator
Identify Fonts - The Font Squirrel Matcherator
Upload an image with type and we’ll identify the fonts that match.
🌐
GitHub
github.com › gaborcselle › font-identifier
GitHub - gaborcselle/font-identifier: Font identifier - given an image, output what font is inside it · GitHub
November 14, 2023 - Font identifier - given an image, output what font is inside it - gaborcselle/font-identifier
Author   gaborcselle