Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Add ability to add custom picture to labels #32

Open
steele-ntwrk opened this issue Jul 11, 2022 · 4 comments
Open

FR: Add ability to add custom picture to labels #32

steele-ntwrk opened this issue Jul 11, 2022 · 4 comments
Assignees

Comments

@steele-ntwrk
Copy link

Hi,

This feature request is to add the ability to add a custom picture to labels such as organization logos. The image could be kept in a local folder or be referenced using a file path.

Thoughts?

Cheers,
Steele

@steele-ntwrk steele-ntwrk changed the title FR: Add ability to add custom picture to tags FR: Add ability to add custom picture to labels Jul 11, 2022
@k01ek
Copy link
Collaborator

k01ek commented Aug 11, 2022

Hi @steele-ntwrk ! Do you mean logo inside the QR code, or put logo next to qr code image instead of text?

@steele-ntwrk
Copy link
Author

Hi @k01ek, Apologies I should be more specific, but a possibly an image on the right-hand side of text or to replace text.

I think maybe a Boolean value to add an image, the image path could be defined via ENV variable.

I am sort of new to programming and have been thinking about adding to this project as my first.

Cheers,
steele

@k01ek k01ek assigned k01ek and steele-ntwrk and unassigned k01ek Feb 8, 2023
@ashokthangaraj
Copy link

@k01ek if you provide an option to update the logo inside the QR code that will be awesome.

@tpx-mk
Copy link

tpx-mk commented Jul 17, 2024

I found a manual how to insert logos into an QRcode at https://www.geeksforgeeks.org/how-to-generate-qr-codes-with-a-custom-logo-using-python/ and managed to transfer the necessary bits to this plugin:

utilities.py:

  • change all Image.newcalls to the Option RGB instead of P or L
  • add a new function (which overloads the existing one without logo):
def get_qr(text, logofile, **kwargs):
    # extracted from example from https://www.geeksforgeeks.org/how-to-generate-qr-codes-with-a-custom-logo-using-python/

    logo = Image.open(logofile)
    basewidth = 100

    # adjust image size
    wpercent = (basewidth/float(logo.size[0]))
    hsize = int((float(logo.size[1])*float(wpercent)))
    logo = logo.resize((basewidth, hsize), Image.Resampling.LANCZOS)

    qr = qrcode.QRCode(**kwargs)
    qr.add_data(text)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white").convert('RGB')

    # set size of QR code
    pos = (
        (img.size[0] - logo.size[0]) // 2,
        (img.size[1] - logo.size[1]) // 2
    )
    img.paste(logo, pos)

    return img

template_content.py:

  • replace line qr_img = get_qr(url, **qr_args)
    with
        if config.get('custom_logo'):
                logofile = config.get('custom_logo')
                qr_img = get_qr(url, logofile, **qr_args)
        else:
                qr_img = get_qr(url, **qr_args)

In the netbox configuration.py you can add a plugin option custom_logo now which points to to logo image file to include.

It's still a rudimentary quick hack but it seems to be working. Please review and consider merging it into the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants