OCR Scanner Template
- Python
- Flask
Pull the text out of a photo, screenshot or scanned page, then copy it.
A Python and Flask app that reads text from images. Drop in a photo, screenshot or scan and get the text it contains, ready to copy, with a character and line count. Use it to digitize receipts and documents, make images searchable, or run it on files and URLs from the command line.

What it does
- Drag, drop, read
- Drop an image or browse for one, preview it, and extract the text in one click.
- Copy the result
- The text keeps its line breaks, with a button to copy it.
- Checks uploads first
- Only JPG, PNG or GIF images of 4 MB or less, within Vercel’s request limit.
- Keeps your key private
- The page calls a server route that holds the key, checks the input and limits each visitor to 10 scans a minute.
- A web app and a CLI
- python app.py runs the page locally. The CLI reads local files or image URLs.
How it works
The Flask route: it checks the upload and sends it to Image to Text.
# Vercel caps a function's request body at 4.5 MB, so uploads stop at 4 MB.
MAX_BYTES = 4 * 1024 * 1024
TYPES = {'image/jpeg', 'image/png', 'image/gif'}
@app.post('/api/scan')
def scan():
"""POST /api/scan (multipart, field "image"): the text in an image."""
image = request.files.get('image')
if not image or not image.filename:
return fail('Choose an image with text in it.')
if image.mimetype not in TYPES:
return fail('Use a JPG, PNG or GIF image.')
data = image.read(MAX_BYTES + 1)
if len(data) > MAX_BYTES:
return fail('Images must be 4 MB or smaller.')
return jsonify(call_api('imagetotext', files={'image': (image.filename, data, image.mimetype)}))Deploy it
- Get a free API key
The free plan includes 200 credits a month, no card needed. Create your key.
- Deploy it
Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for
APIVERVE_API_KEY: paste your key there. - Open your app
Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.
Try the Image to Text API — the call this template makes
No key required to try it. Get a key to use it in your app.
{
"status": "ok",
"error": null,
"data": {
"text": "A year after that (in 2021) I hired somebody tp#lp me write blog posts for\nmy personal website.\n\nThe point is, | like reinvesting the money | make\nback into my business.",
"words": 32,
"characters": 169,
"lines": 5,
"language": [
"en"
],
"confidence": 87.7,
"wordBoxes": [
{
"text": "after",
"confidence": 96.7,
"left": 76,
"top": 19,
"width": 35,
"height": 13,
"block": 1,
"line": 1
},
{
"text": "that",
"confidence": 96.9,
"left": 115,
"top": 19,
"width": 30,
"height": 12,
"block": 1,
"line": 1
},
{
"text": "tp#lp",
"confidence": 62.6,
"left": 357,
"top": 19,
"width": 49,
"height": 16,
"block": 1,
"line": 1
},
{
"text": "business.",
"confidence": 96.9,
"left": 174,
"top": 150,
"width": 99,
"height": 20,
"block": 3,
"line": 2
}
]
}
}