Self-Hosted PHP QR Code Generator Webhook API Documentation

Deployment Note: This package is designed for easy deployment on environments like aapanel with OpenLiteSpeed and PHP 8.1. Ensure the GD extension is enabled in your PHP configuration.

Overview

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.

API Endpoint

The primary endpoint for QR code generation is:

[YOUR_DOMAIN]/api/generate.php

Request Method

The API supports both **GET** and **POST** requests.

Parameters

The API accepts the following parameters:

},{find:
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.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

Error Correction Levels (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

Response

The API returns the generated QR code image directly.

Usage Examples

1. Basic Webhook Call (GET)

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">

2. Advanced Webhook Call (GET)

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

3. Using cURL (POST)

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'

4. Using Python 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}")

Deployment Notes (aapanel/OpenLiteSpeed)

  1. **Upload:** Upload the contents of the `qr_generator` folder (including `index.html`, `api/generate.php`, `api/phpqrcode.php`, and the `docs/` folder) to your website's root directory (e.g., `/www/wwwroot/yourdomain.com/`).
  2. **Permissions:** Ensure the files have correct read permissions (e.g., `644`).
  3. **PHP Version:** The script is compatible with **PHP 8.1** and requires the **GD extension** to be enabled, which is standard on most PHP installations.
  4. **URL Rewriting:** OpenLiteSpeed should handle the routing correctly. If you are using a subdirectory, adjust the example URLs accordingly. If you encounter issues, ensure your OpenLiteSpeed vHost configuration allows PHP execution in the `/api/` directory.

Documentation Author: Manus AI