This document provides instructions on how to call the self-hosted PHP QR Code Generator API. This API is a simple, single-file solution that accepts parameters via **GET** or **POST** requests and returns the generated QR code image directly as a **PNG** file. This makes it ideal for use as a webhook endpoint in various applications.
The primary endpoint for QR code generation is:
[YOUR_DOMAIN]/api/generate.php
The API supports both **GET** and **POST** requests.
<img> tags.The API accepts the following parameters:
| Parameter | Type | Required | Description | Example Value |
|---|---|---|---|---|
data |
string | Yes | The text, URL, or any other data you wish to encode in the QR code. | https://www.example.com |
size |
integer | No | The **module size** (scale factor) in pixels. This determines the final size of the QR code. A larger value means a larger image. The value is clamped between 1 and 20. Default is 4. | },{find:
8 |
margin |
integer | No | The size of the quiet border (white space) around the QR code modules. Default is 4. |
2 |
ecc |
string | No | Error Correction Level. Determines the amount of data that can be recovered if the QR code is damaged. Accepts L, M, Q, or H. |
M |
ecc)The ecc parameter accepts one of four values, corresponding to the percentage of the code that can be damaged and still be readable:
| Value | Level | Recovery Capacity | Default |
|---|---|---|---|
L |
Low | ~7% of data can be restored | |
M |
Medium | ~15% of data can be restored | |
Q |
Quartile | ~25% of data can be restored | |
H |
High | ~30% of data can be restored | Yes |
The API returns the generated QR code image directly.
Content-Type: image/png header, and the body will contain the binary PNG image data.data parameter is missing, the response will have a Content-Type: application/json header, an HTTP status code of **400 Bad Request**, and a JSON body:
{"error": "The \"data\" parameter is required."}
This is the simplest way to call the API, suitable for embedding the QR code directly into a webpage using an <img> tag.
URL:
[YOUR_DOMAIN]/api/generate.php?data=Hello%20World%20from%20Webhook
HTML Example:
<img src="[YOUR_DOMAIN]/api/generate.php?data=My%20Product%20ID%2012345&size=8&ecc=Q" alt="QR Code">
Specify a custom size and error correction level.
URL:
[YOUR_DOMAIN]/api/generate.php?data=https://docs.manus.im&size=10&margin=1&ecc=M
For automated systems or when the data is very long, a POST request is cleaner.
curl -X POST \ '[YOUR_DOMAIN]/api/generate.php' \ -d 'data=This%20is%20a%20very%20long%20string%20of%20data%20that%20should%20be%20encoded%20in%20the%20QR%20code%20using%20a%20POST%20request%20for%20better%20compatibility.' \ -o 'my_qrcode.png'
requests (Webhook Integration)This example shows how an external system can call the API and save the resulting image.
import requests
api_url = "[YOUR_DOMAIN]/api/generate.php"
payload = {
"data": "Order-45678-Tracking-Link",
"size": 7,
"ecc": "H"
}
try:
response = requests.get(api_url, params=payload, stream=True)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
if response.headers['Content-Type'] == 'image/png':
with open('order_qr.png', 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print("QR code saved as order_qr.png")
else:
print(f"Error generating QR code: {response.text}")
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
Documentation Author: Manus AI