Prompt
How do I extract text from JPG and PNG files with OCR?
Latest observation
Oct 11, 2026
OpenAI APIWeb search: off
You can extract text from JPG and PNG images using OCR (Optical Character Recognition).
Common ways to do it
1) Python with Tesseract
Install:
pip install pytesseract pillow
You also need the Tesseract OCR engine installed on your system:
- Windows: install from the Tesseract installer
- macOS:
brew install tesseract - Ubuntu/Debian:
sudo apt install tesseract-ocr
Example:
from PIL import Image
import pytesseract
img = Image.open("image.jpg")
text = pytesseract.image_to_string(img)
print(text)
For PNG, use the same code:
img = Image.open("image.png")
text = pytesseract.image_to_string(img)
print(text)
2) Python with OpenCV + Tesseract
Useful if you want to preprocess the image first for better accuracy.
pip install opencv-python pytesseract
Example:
import cv2
import pytesseract
img = cv2.imread("image.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
text = pytesseract.image_to_string(gray)
print(text)
3) Online OCR tools
If you don’t want to code, you can use web tools like:
- Google Drive OCR
- Adobe Acrobat online OCR
- OnlineOCR.net
4) Cloud OCR APIs
For higher accuracy and production use:
- Google Cloud Vision
- AWS Textract
- Azure Computer Vision
Tips for better OCR accuracy
- Use clear, high-resolution images
- Crop to the text region
- Convert to grayscale
- Improve contrast
- Remove noise
- Rotate/deskew if needed
Example preprocessing:
import cv2
import pytesseract
img = cv2.imread("image.png")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)[1]
text = pytesseract.image_to_string(thresh)
print(text)
If you want, I can also show you:
- how to do OCR on multiple images in a folder, or
- how to extract text from images in a PDF.