Convert Text Image to Hand Written Text Image using Python
Last Updated :
29 Jun, 2021
In this article, we are going to see how to convert text images to handwritten text images using PyWhatkit, Pillow, and Tesseract in Python.
Module needed:
Pytesseract: Sometimes known as Python-tesseract, is a Python-based optical character recognition (OCR) program. It can read and recognize text in photos, license plates, and other documents. To interpret the words from the provided image, we'll utilize the tesseract software.
pip install pytesseract
Pywhatkit: It is a library that may be used for a variety of things, including sending WhatsApp messages, watching YouTube videos, searching Google, and writing handwritten text.
pip install pywhatkit
Pillow: This module adds more features, operates on all major operating systems, and has Python 3 support. It supports a broad range of image formats, including "jpeg," "png," "bmp," "gif," "ppm," and "tiff." With the pillow module, you can do nearly anything with digital photographs.
pip install Pillow
Note: Visit and Install Tesseract; scroll down to find the latest installers for 32-bit and 64-bit systems; download them as needed.
Stepwise implementation:
Step 1: Import the following modules.
Python3
import pytesseract
from PIL import Image
import os
import pywhatkit as kit
Step 2: Navigate to the path where the picture is located, the chdir function in the OS module can be used to alter the directory.
Python3
os.chdir(r"C:\Users\Dell\Downloads")
Step 3: Copy the installation path for Tesseract, paste it here, or verify the directory of Tesseract and copy the entire path.
Python3
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Dell\AppData\Local\/
Tesseract-OCR\tesseract.exe"
Step 4: First, open the image with the image function, then use pytesseract to get all the image's data, and store all the text in a variable.
Python3
img = Image.open("GFG.png")
text = pytesseract.image_to_string(img)
Step 5: Use the text _to_handwriting function from pywhatkit to convert text to the specified RGB color; in this case, the RGB for blue is 0, 0, 250.
Python3
kit.text_to_handwriting(text, rgb=[0, 0, 250])
Below is the complete implementation:
Python3
# Import the following modules
import pytesseract
from PIL import Image
import os
import pywhatkit as kit
# Change the directory to the
# location where image is present
os.chdir(r"C:\Users\Dell\Downloads")
# Set the Path of Tesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\Users\Dell\AppData\/
Local\Tesseract-OCR\tesseract.exe"
# Load the Image
img = Image.open("GFG.png")
# Convert Image to Text
text = pytesseract.image_to_string(img)
# Convert Text to Hand Written Text
kit.text_to_handwriting(text, rgb=[0, 0, 250])
Output:
Similar Reads
Convert Text and Text File to PDF using Python
PDFs are one of the most important and widely used digital media. PDF stands for Portable Document Format. It uses .pdf extension. It is used to present and exchange documents reliably, independent of software, hardware, or operating system. Converting a given text or a text file to PDF (Portable Do
3 min read
Convert PDF to Image using Python
Many tools are available on the internet for converting a PDF to an image. In this article, we are going to write code for converting pdf to image and make a handy application in python. Before writing the code we need to install the required module pdf2image and poppler.Modules Neededpdf2image 1.14
2 min read
Convert image to binary using Python
In this article, we are going to convert the image into its binary form. A binary image is a monochromatic image that consists of pixels that can have one of exactly two colors, usually black and white. Binary images are also called bi-level or two-level. This means that each pixel is stored as a si
1 min read
How to rotate an image using Python?
In this article, let's see how to rotate an Image using Python. By Image Rotation, the image is rotated about its center by a specified number of degrees. The rotation of an image is a geometric transformation. It can be done either by Forward Transformation (or) Inverse Transformation. Here Image P
2 min read
Convert PNG to JPG using Python
PNG and JPG formats are used for image illustrations. Both the formats are used to provide good compatibilities with certain types of images like PNG works better with line drawings and icon graphics whereas JPG works well with photographs. However, both are interconvertible with respect to each oth
3 min read
How to Create Image Quotes Using Python Quote2Image
The Quote2Image is a powerful and fun Python library that can be used to transform text quotes into images. This library allows us to create customized quote images with various styling options. We can use it for social media content, presentations, etc. We can generate them with a single function a
5 min read
How to Convert Image to PDF in Python?
img2pdf is an open source Python package to convert images to pdf format. It includes another module Pillow which can also be used to enhance image (Brightness, contrast and other things) Use this command to install the packages pip install img2pdf  Below is the implementation: Image can be convert
1 min read
How to convert a PDF file to TIFF file using Python?
This article will discover how to transform a PDF (Portable Document Format) file on your local drive into a TIFF (Tag Image File Format) file at the specified location. We'll employ Python's Aspose-Words package for this task. The aspose-words library will be used to convert a PDF file to a TIFF fi
3 min read
How to make background image transparent using Python?
In this article, the task is to create a background transparent of the image in Python Library Required : First Install pillow library on your Python Application before going ahead. Python Imaging Library is a free and open-source additional library for the Python programming language that adds supp
1 min read
How to find width and height of an image using Python?
In this article, we are going to discuss how to get the height and width of a particular image. In order to find the height and width of an image, there are two approaches. The first approach is by using the PIL(Pillow) library and the second approach is by using the Open-CV library. Approach 1: PIL
2 min read