QR Code image generator with customizable image formats, error correction levels, and styling options
Build a utility that demonstrates control over QR code versions to generate codes of specific sizes.
Your task is to create a Python module that:
Generates QR codes with explicit version control: Create QR codes where you specify the exact version (size) of the QR code, ranging from version 1 (21x21 modules) to version 40 (177x177 modules).
Calculates version dimensions: Given a version number, calculate and return the matrix dimensions (width and height in modules) for that QR code version. Each version number corresponds to a specific size: version N has dimensions of (17 + 4N) x (17 + 4N) modules.
Finds minimum version for data: Given input data and an error correction level, determine the smallest QR code version that can accommodate that data.
Create a module with the following functions:
create_qr_with_version(data: str, version: int, error_correction: str = "M") -> objectCreates a QR code with a specific version number.
data: The text/data to encode in the QR codeversion: An integer from 1 to 40 specifying the QR code versionerror_correction: Error correction level ("L", "M", "Q", or "H")get_version_dimensions(version: int) -> dictReturns the dimensions of a QR code for a given version.
version: An integer from 1 to 40"width" and "height" representing the number of modules in each dimensionfind_minimum_version(data: str, error_correction: str = "M") -> intDetermines the smallest version that can fit the given data.
data: The text/data that needs to be encodederror_correction: Error correction level ("L", "M", "Q", or "H")Provides QR code generation capabilities with version control and error correction options.
@satisfied-by
@generates
def create_qr_with_version(data: str, version: int, error_correction: str = "M") -> object:
"""
Creates a QR code with a specific version number.
Args:
data: The text/data to encode in the QR code
version: An integer from 1 to 40 specifying the QR code version
error_correction: Error correction level ("L", "M", "Q", or "H")
Returns:
A QR code object that can be rendered to an image
"""
pass
def get_version_dimensions(version: int) -> dict:
"""
Returns the dimensions of a QR code for a given version.
Args:
version: An integer from 1 to 40
Returns:
A dictionary with keys "width" and "height" representing module dimensions
"""
pass
def find_minimum_version(data: str, error_correction: str = "M") -> int:
"""
Determines the smallest version that can fit the given data.
Args:
data: The text/data that needs to be encoded
error_correction: Error correction level ("L", "M", "Q", or "H")
Returns:
The minimum version number that can accommodate the data
"""
passevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10