From 5deddf1c559690d3f0ee256893aeef02a875d2f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Opali=C5=84ski?= Date: Thu, 5 Jun 2025 14:26:56 +0200 Subject: [PATCH 1/3] Add additional parameters to get_qr to allow customization --- netbox_qrcode/utilities.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/netbox_qrcode/utilities.py b/netbox_qrcode/utilities.py index e0cd376..e849829 100644 --- a/netbox_qrcode/utilities.py +++ b/netbox_qrcode/utilities.py @@ -13,10 +13,16 @@ # text: Text to be included in the QR code. # **kwargs: List of parameters which properties the QR code should have. (e.g. version, box_size, error_correction, border etc.) def get_qr(text, **kwargs): - qr = qrcode.QRCode(**kwargs) + qr_kwargs = {key: value for key, value in kwargs.items() if key != 'image_kwargs'} + qr = qrcode.QRCode(**qr_kwargs) qr.add_data(text) qr.make(fit=True) - img = qr.make_image() + + if 'image_kwargs' in kwargs: + img = qr.make_image(**kwargs['image_kwargs']) + else: + img = qr.make_image() + img = img.get_image() return img From dfc97ba4c42504390bb41f5eb61d4c5785b15723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Opali=C5=84ski?= Date: Thu, 5 Jun 2025 14:28:33 +0200 Subject: [PATCH 2/3] Add example configuration for styled QR code --- develop/configuration.py | 19 +++++++++++++++++++ develop/docker-compose.yml | 1 + 2 files changed, 20 insertions(+) diff --git a/develop/configuration.py b/develop/configuration.py index fdc1217..6786e96 100644 --- a/develop/configuration.py +++ b/develop/configuration.py @@ -155,6 +155,12 @@ # Enable installed plugins. Add the name of each plugin to the list. PLUGINS = ["netbox_qrcode"] +import qrcode +from qrcode.image.styledpil import StyledPilImage +from qrcode.image.styles.moduledrawers import GappedSquareModuleDrawer +from qrcode.image.styles.colormasks import RadialGradiantColorMask +from PIL import ImageColor + # Plugins configuration settings. These settings are used by various plugins that the user may have installed. # Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings. PLUGINS_CONFIG = { @@ -176,6 +182,19 @@ 'label_edge_left': '2mm', 'label_edge_right': '2mm', 'logo': '/media/image-attachments/Netbox_Icon_Example.png', + + # Styled QR image with radial gradient, gapped squares and embedded image + 'qr_error_correction': qrcode.constants.ERROR_CORRECT_H, + 'qr_image_kwargs': { + 'image_factory': StyledPilImage, + 'module_drawer': GappedSquareModuleDrawer(), + 'color_mask': RadialGradiantColorMask( + back_color=ImageColor.getrgb("#ffffff"), + center_color=ImageColor.getrgb("#6642d3"), + edge_color=ImageColor.getrgb("#386bf1") + ), + 'embedded_image_path': "/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png", + }, }, 'device_3': { diff --git a/develop/docker-compose.yml b/develop/docker-compose.yml index 285f481..3d293a9 100644 --- a/develop/docker-compose.yml +++ b/develop/docker-compose.yml @@ -18,6 +18,7 @@ services: volumes: - ./configuration.py:/opt/netbox/netbox/netbox/configuration.py - ../docs/img/Netbox_Icon_Example.png:/opt/netbox/netbox/media/image-attachments/Netbox_Icon_Example.png + - ./Netbox_Icon.png:/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png - ../netbox_qrcode:/source/netbox_qrcode tty: true worker: From d93879af94a2e4f6d8e60010527b4e809cfea9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Opali=C5=84ski?= Date: Thu, 5 Jun 2025 14:39:09 +0200 Subject: [PATCH 3/3] Fix example configuration --- develop/configuration.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/develop/configuration.py b/develop/configuration.py index 6786e96..c38ac98 100644 --- a/develop/configuration.py +++ b/develop/configuration.py @@ -182,19 +182,6 @@ 'label_edge_left': '2mm', 'label_edge_right': '2mm', 'logo': '/media/image-attachments/Netbox_Icon_Example.png', - - # Styled QR image with radial gradient, gapped squares and embedded image - 'qr_error_correction': qrcode.constants.ERROR_CORRECT_H, - 'qr_image_kwargs': { - 'image_factory': StyledPilImage, - 'module_drawer': GappedSquareModuleDrawer(), - 'color_mask': RadialGradiantColorMask( - back_color=ImageColor.getrgb("#ffffff"), - center_color=ImageColor.getrgb("#6642d3"), - edge_color=ImageColor.getrgb("#386bf1") - ), - 'embedded_image_path': "/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png", - }, }, 'device_3': { @@ -258,6 +245,19 @@ 'label_edge_right': '0mm', 'with_text': False, 'with_qr': True, + + # Styled QR image with radial gradient, gapped squares and embedded image + 'qr_error_correction': qrcode.constants.ERROR_CORRECT_H, + 'qr_image_kwargs': { + 'image_factory': StyledPilImage, + 'module_drawer': GappedSquareModuleDrawer(), + 'color_mask': RadialGradiantColorMask( + back_color=ImageColor.getrgb("#ffffff"), + center_color=ImageColor.getrgb("#6642d3"), + edge_color=ImageColor.getrgb("#386bf1") + ), + 'embedded_image_path': "/opt/netbox/netbox/media/image-attachments/Netbox_Icon.png", + }, }, 'device_7': {