Miscellaneous tools

misc.py module

The misc module contains general-purpose helper tools that support the broader ecosystem of pyphyschemtools. This includes project branding.

So far, it only contains the QRcodeGenerator class

Branded QR Code Generation

The QRCodeGenerator class allows you to create customized QR codes with an embedded logo. This is particularly useful for linking physical lab documents or posters to digital documentation.

Here is how to generate a QR code pointing to the project repository with the official logo centered:

from pyphyschemtools.tools4AS.misc import QRCodeGenerator

gen = QRCodeGenerator()
# This will save to 'images/qrcode_Logo.png' and display it automatically
gen.generate(
    url="https://github.com/rpoteau/pyPhysChem",
    logo_path="images/Logo.png",
    fill_color="#1a525f", #default hex code or name for the QR code color
    back_color="white", #default name of the background color
    logo_ratio=4, #default ratio of logo size relative to QR code size
    flatten=True # removes transparency by placing the logo on a solid white background. Defaults to False.
)

API reference

class pyphyschemtools.misc.QRCodeGenerator(box_size=40, border=1, version=4)[source]

Bases: object

A utility class to generate QR codes with embedded logos for pyphyschemtools. Initialize the generator with specific QR parameters.

Parameters:
  • box_size (int) – The size of each box in the QR code grid.

  • border (int) – The thickness of the white border.

  • version (int) – The complexity of the QR code (1 to 40).

generate(url, logo_path, fill_color='#1a525f', back_color='white', save_path=None, logo_ratio=4, width=250, flatten=False)[source]

Creates a QR code with a centered logo, saves it to disk, and displays it.

If save_path is not provided, the image is saved in the logo’s directory with a qrcode_ prefix.

Parameters:
  • url (str) – The target URL for the QR code.

  • logo_path (str) – Path to the logo image file.

  • fill_color (str) – Hex code or name for the QR code color.

  • back_color (str) – Background color.

  • save_path (str, optional) – Custom path to save the PNG. Defaults to None.

  • logo_ratio (float) – Ratio of logo size relative to QR code size (default 1/4).

  • width (int) – Display width for Jupyter Notebook rendering.

  • flatten (bool) – If True, removes transparency by placing the logo on a solid white background. Defaults to False.

Returns:

The generated QR code image object.

Return type:

PIL.Image