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.

The ocr scanner app running

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.

app.py
# 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)}))

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. 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

Request
POSTapi.apiverve.com/v1/imagetotext
image
Click or drag a file to upload.jpg, .jpeg, .png, .gif · max 400KB for live testing
Verification
Format

No key required to try it. Get a key to use it in your app.

Example
{
  "status": "ok",
  "error": null,
  "data": {
    "text": "Ayear after that (in 2021) I hired somebody tpHfelp me write blog posts for\nmy personal website.\n\nThe point is, | like reinvesting the money | make\nback into my business.",
    "words": 28,
    "characters": 170,
    "lines": 5
  }
}

Build your own with Image to Text. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs