diff --git a/develop/configuration.py b/develop/configuration.py index fdc1217..c38ac98 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 = { @@ -239,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': { 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: 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