Skip to content

QR Code Generation

The /qrcode endpoint generates a QR Code from a URL provided as a parameter. This endpoint is useful for quickly generating an image in PNG format.

Parameters

ParameterRequiredDescription
urlYesThe URL to encode in the QR Code. Must contain the full address
formatNoResponse format: png (default, direct image) or base64 (JSON data URL)
sizeNoImage size in pixels (50-2000, default 200)
marginNoQuiet zone in modules (0-10, default 4)
correctionNoError correction level: L, M, Q or H (default M)
darkNoModule color in hexadecimal (e.g. 000000)
lightNoBackground color in hexadecimal (e.g. ffffff)
iconNoHTTPS URL of an image to overlay at the center of the QR Code
iconSizeNoIcon size in pixels (default 20% of size, max 40% of size)
iconPaddingNoWhite padding around the icon in pixels (default 5, 0-50)
iconRadiusNoBorder radius of the icon background in pixels (default 0, max = perfect circle)

Good to know

When an icon is provided, the error correction level is automatically set to H to ensure readability. The icon URL must use HTTPS, with a 5s timeout and a 2MB size limit.

Keep the icon small

A large iconSize combined with generous iconPadding covers more QR Code modules, making it harder to scan. Keep the icon + padding area well below 40% of the total size for reliable results.

Response

By default (format=png), the endpoint returns a direct PNG image (Content-Type: image/png), usable in an <img> tag:

html
<img src="https://api.sylvain.sh/v4/qrcode?url=https://docs.sylvain.sh" alt="QR Code" />

With format=base64, the response is a JSON object:

FieldTypeDescription
resultstringBase64 PNG data URI of the QR Code

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v4/qrcode?url=https%3A%2F%2Fdocs.sylvain.sh&size=300&margin=2&dark=1a1a2e&light=eaeaea"

Try It

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide a valid URLThe url parameter is missing or invalid
format must be one of: png, base64Invalid format value
size must be a numberThe size parameter is not a number
size must be between 50 and 2000The size is out of range
margin must be a numberThe margin parameter is not a number
margin must be between 0 and 10The margin is out of range
correction must be one of: L, M, Q, HInvalid error correction level
Invalid color (use hex like ff6600)A dark or light color is malformed
Icon URL must use HTTPSThe icon URL does not use HTTPS
Failed to fetch icon: HTTP {status}The icon URL returned a non-OK response
Icon URL must point to an imageThe icon content-type is not an image
Icon must be under 2MBThe icon exceeds the 2MB size limit
iconSize must be a numberThe iconSize parameter is not a number
iconSize must be between 10 and {max}The iconSize is out of range (max = 40% of size)
iconPadding must be a numberThe iconPadding parameter is not a number
iconPadding must be between 0 and 50The iconPadding is out of range
iconRadius must be a numberThe iconRadius parameter is not a number
iconRadius must be between 0 and {max}The iconRadius is out of range