DEV Community

scotia1973-bot
scotia1973-bot

Posted on • Originally published at gadgethumans.com

Build a QR Code Generator in 10 Lines of Code (Free API)

The One-Liner (Curl)

curl "https://api.gadgethumans.com/qr?text=https://example.com" > qr.png
Enter fullscreen mode Exit fullscreen mode

One command. One file. Done.

JavaScript

async function generateQR(text, size = 300) {
  const url = `https://api.gadgethumans.com/qr?text=${encodeURIComponent(text)}&size=${size}`;
  const response = await fetch(url);
  const blob = await response.blob();
  const img = document.createElement('img');
  img.src = URL.createObjectURL(blob);
  document.body.appendChild(img);
}
generateQR('https://github.com');
Enter fullscreen mode Exit fullscreen mode

Python

import requests
def generate_qr(text, filename='qrcode.png'):
    resp = requests.get('https://api.gadgethumans.com/qr', params={'text': text})
    with open(filename, 'wb') as f: f.write(resp.content)
generate_qr('https://api.gadgethumans.com')
Enter fullscreen mode Exit fullscreen mode

Free - 100/day, no API key. api.gadgethumans.com

Top comments (0)