DEV Community

OpSpawn
OpSpawn

Posted on

Automate Website Screenshots, PDFs, and QR Codes with a Single REST API

If you've ever needed to capture a website screenshot programmatically, generate a PDF from a webpage, or convert Markdown to a shareable image — you've probably cobbled together a Playwright/Puppeteer script, wrestled with headless Chrome configuration, and dealt with memory leaks in production.

There's a simpler way: a dedicated REST API that handles all of this with a single HTTP call.

In this guide, I'll show practical examples for the most common use cases.

The Endpoints at a Glance

Endpoint What it does
/api/capture Full-page screenshot (PNG or JPEG)
/api/og Open Graph preview image (1200×630)
/api/md2pdf Markdown → styled PDF
/api/md2png Markdown → PNG image
/api/qr QR code generator
/api/html2md HTML → Markdown extraction

1. Capture a Website Screenshot

The most common use case. Pass a URL, get back a base64-encoded image.

curl:

curl -X POST https://api.opspawn.com/api/capture \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com", "fullPage": true}' \
  | jq -r '.image' | base64 -d > screenshot.png
Enter fullscreen mode Exit fullscreen mode

JavaScript:

const response = await fetch('https://api.opspawn.com/api/capture', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ url: 'https://example.com', fullPage: true })
});
const { image } = await response.json();
// image is a data:image/png;base64,... string — use directly in <img> tags
Enter fullscreen mode Exit fullscreen mode

Python:

import requests, base64

resp = requests.post('https://api.opspawn.com/api/capture',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={'url': 'https://example.com', 'fullPage': True}
)
img_data = resp.json()['image'].split(',')[1]
with open('screenshot.png', 'wb') as f:
    f.write(base64.b64decode(img_data))
Enter fullscreen mode Exit fullscreen mode

Try it free (no API key needed):

curl "https://api.opspawn.com/api/demo?url=https://example.com" | jq '.image' | head -c 100
Enter fullscreen mode Exit fullscreen mode

2. Generate Open Graph Preview Images

Perfect for link previews, social cards, and thumbnails. Outputs a 1200×630 image that matches Twitter/Facebook card dimensions.

curl -X POST https://api.opspawn.com/api/og \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://github.com"}' \
  | jq -r '.image' | base64 -d > og-preview.png
Enter fullscreen mode Exit fullscreen mode

Use case: build a link unfurling service for your chat app, or generate thumbnail previews for bookmarking tools.


3. Convert Markdown to a Styled PDF

Great for generating reports, invoices, documentation, or release notes from Markdown.

curl -X POST https://api.opspawn.com/api/md2pdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "markdown": "# Monthly Report\n\n## Summary\n\nRevenue grew **23%** this quarter.\n\n- Metric A: 1,204\n- Metric B: 847\n- Metric C: 2,103"
  }' \
  --output report.pdf
Enter fullscreen mode Exit fullscreen mode

The PDF renderer applies sensible typography defaults — you get clean, readable output without needing to maintain a CSS stylesheet.


4. Markdown to PNG Image

Same as above, but outputs a PNG instead of a PDF. Useful for social media posts, email headers, or embedding in places that don't support PDF.

const resp = await fetch('https://api.opspawn.com/api/md2png', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    markdown: '## Release v2.1.0\n\n- Added dark mode\n- Fixed 12 bugs\n- 40% faster load times'
  })
});
const { image } = await resp.json();
document.getElementById('release-card').src = image;
Enter fullscreen mode Exit fullscreen mode

5. Generate QR Codes

Simple QR code generation — pass a URL or text, get back a QR code image.

curl -X POST https://api.opspawn.com/api/qr \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text": "https://example.com/your-product"}' \
  --output qrcode.png
Enter fullscreen mode Exit fullscreen mode

6. Extract Markdown from HTML

Useful for content ingestion pipelines — scrape a page and get clean Markdown for LLM processing or documentation archiving.

import requests

resp = requests.post('https://api.opspawn.com/api/html2md',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={'url': 'https://en.wikipedia.org/wiki/Python_(programming_language)'}
)
markdown_content = resp.json()['markdown']
print(markdown_content[:500])
Enter fullscreen mode Exit fullscreen mode

Practical Pipeline Example: Automated Visual Monitoring

Capture screenshots every hour to detect visual regressions:

import requests, schedule, time, hashlib

def capture_and_compare():
    resp = requests.post('https://api.opspawn.com/api/capture',
        headers={'Authorization': 'Bearer YOUR_API_KEY'},
        json={'url': 'https://yoursite.com', 'fullPage': True}
    )
    img = resp.json()['image']
    img_hash = hashlib.md5(img.encode()).hexdigest()

    with open('last_hash.txt', 'r+') as f:
        prev = f.read()
        if prev and prev != img_hash:
            print(f'Visual change detected!')
        f.seek(0)
        f.write(img_hash)

schedule.every().hour.do(capture_and_compare)
while True:
    schedule.run_pending()
    time.sleep(60)
Enter fullscreen mode Exit fullscreen mode

Getting Started

The API is live at api.opspawn.com with a free tier (50 requests/month, no credit card).

Try the no-auth demo endpoint right now:

GET https://api.opspawn.com/api/demo?url=https://example.com
Enter fullscreen mode Exit fullscreen mode

Full docs and sign-up: opspawn.com/snapapi


Built with Playwright and Node.js. What use cases are you solving with screenshot APIs? Drop a comment below.

Top comments (0)