Frequently Asked Question

QR: An Advanced and Customisable QR Code Generator
Last Updated 7 days ago

QR Code API

Overview

The QR Code API generates QR codes in various formats (PNG, SVG, HTML) with customizable colors, sizes, error correction levels, and optional logo overlay. It supports encoding URLs, text, vCards, WiFi configurations, and any other data up to 2KB.

image

Version

1.004

Endpoint

/v2/qr

Authentication

This API requires authentication using an API key. The key should be passed in the X-API-Key header.

Request Parameters

ParameterTypeRequiredDefaultDescription
datastringYes*-Raw content to encode in QR code (max 2048 chars). Use for simple text without special URL characters.
data64stringYes*-Base64 encoded content (max 4096 chars). Use for URLs with query strings or special characters. Takes priority over data if both provided.
formatstringNopngOutput format: png (base64), svg, html
sizeintNo3Module size in pixels (1-20). Each QR "square" will be this many pixels. Ignored if width is specified.
widthintNo-Target image width in pixels (50-2000). Overrides size calculation for precise output dimensions.
eclstringNoLError correction level: L (7%), M (15%), Q (25%), H (30%). Higher = more redundancy, larger QR code.
colorstringNo000000Foreground color as 6-digit hex (e.g., FF0000 for red)
bgcolorstringNoFFFFFFBackground color as 6-digit hex (e.g., FFFF00 for yellow)
invertintNo0Swap foreground and background colors: 0 = normal, 1 = inverted
logostringNo-Base64 encoded logo image (PNG, JPG, GIF) to overlay in center. Supports URL-safe base64.
logo_sizeintNo20Percentage of QR code that logo covers (10-30). Larger logos reduce scanability.

* Either data or data64 must be provided.

Response

The API returns a JSON object with the following structure:

FieldTypeDescription
statusstring"success" or error message starting with HTTP code
formatstringOutput format used: "base64", "svg", or "html"
mimetypestringMIME type: "image/png", "image/svg+xml", or "text/html"
datastringThe QR code data (base64 for PNG, raw for SVG/HTML)
datauristringComplete data URI for PNG format (ready for img src)
dimensionsobjectSize information: modules, width, height
logo_appliedbooleanWhether logo was successfully overlaid (only if logo provided)
logo_errorstringError message if logo overlay failed

Example: Simple Text QR Code

Request:

GET /v2/qr?data=Hello+World&format=png&width=200

Response:

{
  "status": "success",
  "format": "base64",
  "mimetype": "image/png",
  "data": "iVBORw0KGgoAAAANS...",
  "datauri": "data:image/png;base64,iVBORw0KGgoAAAANS...",
  "dimensions": {
    "modules": 21,
    "width": 200,
    "height": 200
  }
}

Example: URL with Query String (using data64)

When encoding URLs with & or = characters, use base64 encoding:

Original URL: https://example.com/page?id=123&ref=456

Base64 encoded: aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlP2lkPTEyMyZyZWY9NDU2

GET /v2/qr?data64=aHR0cHM6Ly9leGFtcGxlLmNvbS9wYWdlP2lkPTEyMyZyZWY9NDU2&format=png&width=300

PHP example:

$url = "https://example.com/page?id=123&ref=456";
$data64 = base64_encode($url);
$apiUrl = "https://api.example.com/v2/qr?data64=" . urlencode($data64) . "&format=png";

Example: Custom Colors

GET /v2/qr?data=ColorfulQR&format=png&width=200&color=0066CC&bgcolor=FFFFCC

Creates a blue QR code on a light yellow background.

Example: Inverted Colors

GET /v2/qr?data=InvertedQR&format=png&width=200&invert=1

Creates a white QR code on a black background (or swaps custom colors if specified).

Example: QR Code with Logo

Add a centered logo overlay for branding. The API automatically upgrades to high error correction (H) when a logo is provided.

GET /v2/qr?data=https://example.com&format=png&width=300&logo=iVBORw0KGgo...&logo_size=20

Important notes for logos:

  • Logo should be base64 encoded (PNG, JPG, or GIF)
  • URL-safe base64 is supported (- and _ instead of + and /)
  • Keep logo_size at 20% or less for reliable scanning
  • Simple, high-contrast logos work best
  • Error correction is automatically set to H (30%) when logo is used

PHP example with logo:

$logoData = base64_encode(file_get_contents('logo.png'));
$url = "https://api.example.com/v2/qr?data=https://mysite.com&width=300&logo=" . urlencode($logoData) . "&logo_size=15";

Example: SVG Output

GET /v2/qr?data=VectorQR&format=svg&size=5&color=333333

Response:

{
  "status": "success",
  "format": "svg",
  "mimetype": "image/svg+xml",
  "data": "..."
}

Example: HTML Output

GET /v2/qr?data=HTMLQR&format=html&size=3

Returns div-based HTML that can be embedded directly in web pages.

Error Correction Levels

LevelRecoveryUse Case
L~7%Default. Best for clean display environments.
M~15%Good balance of size and error tolerance.
Q~25%Higher reliability for printed codes.
H~30%Maximum reliability. Required for logo overlay.

Error Handling

  • Missing data: {"status": "400 : Missing required parameter 'data'"}
  • Invalid base64 in data64: Falls back to raw data parameter
  • Generation failure: {"status": "500 : Failed to generate QR code"}
  • PNG generation without GD: {"status": "500 : PNG generation failed - GD or Imagick library required"}
  • Logo overlay failure: Returns QR without logo plus logo_applied: false and logo_error with details

Notes

  • QR codes are always square (width = height).
  • PNG format requires the GD library to be installed on the server.
  • SVG and HTML formats work without any image libraries.
  • The datauri field can be used directly in an image tag.
  • For WiFi QR codes, use format: WIFI:T:WPA;S:NetworkName;P:Password;;
  • For vCards, use standard vCard 3.0 or 4.0 format.
  • Maximum data capacity depends on error correction level and content type.

Security

  • Ensure that the API key is kept secure and not exposed in client-side code.
  • All responses are sent with the "Content-Type: application/json" header.
  • Logo images are validated as proper image formats before processing.
  • Input data is sanitized to prevent injection attacks.
This website relies on temporary cookies to function, but no personal data is ever stored in the cookies.
OK
Powered by GEN UK CLEAN GREEN ENERGY

Loading ...