lincolnloop / python-qrcode

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

Is it possible to round the corners of the alignment sqaures #332

Open macmichael01 opened 1 year ago

macmichael01 commented 1 year ago

I generated a qrcode using the RoundedModuleDrawer() but it does not round the alignment squares. Is it possible with this library?

Here is what I am hoping to achieve:

Screenshot 2023-05-20 at 1 40 18 AM
Vill21 commented 11 months ago

Yes it is possible, though I don't know if there is a way to make blocks more or less round. I've found solution in #329. A QRCode object has a method make_image. There you may pass an argument eye_drawer the same way as module_drawer. I will explain here, how I understand the meaning of each argument. The first one affects alignment blocks while the second one takes control under the other data carrying blocks of a QR code. The example code is provided below.

image = qr.make_image(fill_color="black",
                          back_color="white",
                          image_factory=StyledPilImage,
                          module_drawer=module_drawer(),
                          eye_drawer=module_drawer())

module_drawer here is one of the classes of module drawers. To style a QR code I use StyledPilImage factory with PIL module drawers from qrcode.image.styles.moduledrawers.pil.

This method does not allow to get pictures with alignment blocks to be styled in a way you might expect or so that it can be then successfully scanned. See #329 for an example. And here is what I have after using this method.

qrcode_0