Customizeable QR Code Generator

PAID
By Huzaifa Hashmi | Updated a month ago | Video, Images
Health Check

N/A

README

Overview

This API generates a customizable QR code image in PNG format based on user-provided data and parameters. Users can specify the content, size, border, fill color, background color, style, and logo of the QR code.

API Endpoints

GET /generate_qr: Generates a QR code image and returns it as a PNG file. Accepts the following query parameters:

content: The data to encode in the QR code (required).
size: The size of each box in the QR code in pixels (default is 10).
border: The width of the border around the QR code in boxes (default is 4).
fill_color: The color of the boxes in the QR code (default is black).
back_color: The color of the background in the QR code (default is white).
style: The style of the QR code. Accepts “normal” for standard square boxes or “rounded” for rounded corners (default is “normal”).
logo_url: The URL of the logo to overlay on the center of the QR code (optional).
logo_scale: The scale of the logo relative to the QR code size (default is 0.15).

Example Usage

Here’s an example usage of the API:

import requests

Define the API endpoint

endpoint = ‘http://localhost:5000/generate_qr

Define the query parameters

params = {
‘content’: ‘Hello, world!’,
‘size’: 20,
‘border’: 8,
‘fill_color’: ‘red’,
‘back_color’: ‘yellow’,
‘style’: ‘rounded’,
‘logo_url’: ‘https://www.python.org/static/opengraph-icon-200x200.png’,
‘logo_scale’: 0.2
}

Send the API request

response = requests.get(endpoint, params=params)

Save the QR code image

with open(‘qr_code.png’, ‘wb’) as f:
f.write(response.content)

Code Explanation
The API is built with the Flask web framework and the qrcode and Pillow image processing libraries.

The generate_qr function is the main endpoint of the API. It retrieves the query parameters from the request object and uses them to generate a QR code image using the qrcode library. The function then applies the specified style and logo to the QR code image using the Pillow library.

If the style parameter is set to “rounded”, the function converts the QR code image to RGBA format, creates a circular mask using the Pillow ImageDraw module, applies the mask to the image, and saves the image with transparent background.

If the logo_url parameter is provided, the function downloads the logo image from the URL using the requests library, resizes it to the specified scale, and overlays it on the center of the QR code image using the Pillow paste function.

Finally, the function saves the QR code image to a file and returns it to the client as a PNG file using the Flask send_file function.

Conclusion
That’s it! With this API, you can easily generate customized QR codes for a variety of use cases.

Followers: 0
API Creator:
Rapid account: Huzaifa Hashmi
Huzaifa Hashmi
huzaifahashmi906
Log In to Rate API
Rating: 5 - Votes: 1