File size: 339 Bytes
836bc0e
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import imghdr
from PIL import Image
import pytesseract
from io import BytesIO

def is_image(content):
    return imghdr.what(None, h=content) in ["jpeg", "png", "bmp", "gif", "tiff", "webp"]

def extract_text_from_image_bytes(image_bytes):
    image = Image.open(BytesIO(image_bytes))
    return pytesseract.image_to_string(image).strip()