# OCR Portfolio Image Workflow (IDX / Stockbit)

## Problem
Telegram-uploaded images fail `vision_analyze()` — cannot read canvas-based app screenshots (Stockbit, Ajaib, IPOT, etc.) reliably.

## Solution: tesseract CLI via subprocess

```python
import subprocess

result = subprocess.run(
    ["tesseract", "/path/to/image.jpg", "stdout", "-l", "eng+ind"],
    capture_output=True, text=True, timeout=30
)
print(result.stdout)
```

**Requirements:**
- `tesseract` binary at `/usr/bin/tesseract` (already installed on server)
- No Python OCR libs needed — CLI is sufficient
- Language flags: `-l eng+ind` for English+Indonesian text

## Verified Working Images
| App | Format | Size |
|-----|--------|------|
| Stockbit | JPEG portrait | 576×1280 |
| Generic screenshot | PNG | varies |

## Data Typically Extractable
- Total equity value
- Per-stock: current value, invested amount, P&L (Rp), P&L (%)
- Stock tickers (may need cleanup — "BUMI" vs "BUML" OCR errors)
- Prices may have `,` vs `.` formatting issues — normalize to number

## Post-OCR Parsing Pattern
```python
import re

text = result.stdout
# Extract stock tickers (all-caps, 2-5 chars)
tickers = re.findall(r'\b([A-Z]{4,5})\b', text)
# Extract monetary values
values = re.findall(r'[\d,.]+', text)
```

## Limitation
Small text (metrics tables) may be unreadable. Portrait orientation works better than landscape for mobile app screenshots.
