lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.25k stars 660 forks source link

Possibility to add a logo in the middle #347

Open TWEagle opened 7 months ago

TWEagle commented 7 months ago

Is it possible to add an image in the center of the qr-code?

stvnmbt commented 7 months ago

Yes. From https://github.com/lincolnloop/python-qrcode#styled-image

import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import RoundedModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_L)
qr.add_data('Some data')

img_1 = qr.make_image(image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer())
img_2 = qr.make_image(image_factory=StyledPilImage, color_mask=RadialGradiantColorMask())
img_3 = qr.make_image(image_factory=StyledPilImage, embeded_image_path="/path/to/image.png") # this is what you want
nabelekt commented 4 months ago

Is there a way to control the relative size of the image? E.g., I want the width of the logo to be 40% the width of the QR code.

lsgd commented 1 month ago

Is there a way to control the relative size of the image?

Yes, with pull request #360 this is now possible. Simply set embeded_image_ratio with a value between 0 and 1. Default is 0.25.

nabelekt commented 1 month ago

Yes, with pull request #360 this is now possible. Simply set embeded_image_ratio with a value between 0 and 1. Default is 0.25.

Thanks! I will try it out with the next release. FWIW, I don't know why I put my question in this issue. Seems separate. Either way, this issue can probably be closed.