| name | img2textocr |
| description | Extract text from an image file (PNG, JPG, etc.) using Tesseract OCR and save the result as a .txt file. Automatically crops the top header and bottom footer regions before OCR so that page titles, section headings in the margin, and page numbers are excluded from the output. Use this skill whenever the user wants to convert an image to text, extract body text from a scanned page, or perform OCR on a document image while skipping headers and footers (e.g. "page_033.png์ ํ
์คํธ๋ก ๋ณํํด์ค", "์ด ์ด๋ฏธ์ง์์ ๋ณธ๋ฌธ๋ง ์ถ์ถํด์ค", "img2text๋ก ๋ณํํด์ค").
|
img2textocr
Convert a document image to plain text using Tesseract OCR, with automatic
header/footer removal.
Workflow
- Identify the source image from the user's request (e.g.
artifacts/2017-NEC-Code/page_033.png).
- Determine the output path โ default: same directory, same stem,
.txt extension.
- Run the bundled script via
bash or execute_code:
python skills/img2textocr/scripts/img2textocr.py "<image_path>" "<output_txt_path>"
- Report results โ show the output path and a preview of the extracted text.
Script
scripts/img2textocr.py โ accepts positional and optional arguments:
| Argument | Type | Default | Description |
|---|
image_path | str | โ | Path to the source image (required) |
output_path | str | auto | Output .txt path (default: <image_stem>.txt) |
--top-crop | float | 0.09 | Fraction of height to crop from top (header) |
--bottom-crop | float | 0.04 | Fraction of height to crop from bottom (footer) |
--lang | str | eng | Tesseract language code |
--psm | int | 6 | Tesseract page segmentation mode |
Crop Tuning
The default crop values (top=9%, bottom=4%) are calibrated for standard NEC/NFPA
document scans (1275ร1650 px). Adjust if the header or footer is still visible in
the output:
python skills/img2textocr/scripts/img2textocr.py page.png --top-crop 0.12
python skills/img2textocr/scripts/img2textocr.py page.png --lang kor+eng
Dependencies
pytesseract โ Python wrapper for Tesseract (auto-installed by script)
Pillow โ Image processing (auto-installed by script)
tesseract โ Must be installed on the system (e.g. brew install tesseract)
Example
User says: "artifacts/2017-NEC-Code/page_033.png์ img2text๋ก ๋ณํํด์ค"
python skills/img2textocr/scripts/img2textocr.py \
artifacts/2017-NEC-Code/page_033.png \
artifacts/2017-NEC-Code/page_033.txt
Output: artifacts/2017-NEC-Code/page_033.txt (header/footer excluded)