lincolnloop / python-qrcode

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

`fill_color` and `back_color` not working. #324

Open Liscuri opened 1 year ago

Liscuri commented 1 year ago

It doesn't work in the recent versions. I know it works on older version but would prefer using the newest version for my code.

lucashahnndev commented 12 months ago

I also noticed that it doesn't work if I use "image_factory=StyledPilImage" apart from that "fill_color" and "back_color" WORKS NORMALLY!

kake-r commented 11 months ago

I'm facing the same issue as well.

code

import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import CircleModuleDrawer

qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_M,
    box_size=10,
    border=0,
)

qr.add_data('Some text')
qr.make(fit=True)

img = qr.make_image(
    fill_color="red", 
    back_color="blue",
    image_factory=StyledPilImage, 
    module_drawer=CircleModuleDrawer()
)

img.save('./data/qrcode_test.png')

Environment

Python 3.11.4

Package           Version
----------------- ------------
qrcode            7.4.2
IS0metric commented 10 months ago

I'm also facing this issue. Here is a very minimum example where I am seeing only black and white QR codes being made:

import qrcode
qr = qrcode.QRCode(version = 1, box_size = 10, border = 4)
qr.add_data("myQR")
qr.make(fit = True)
img = qr.make_image(fill_color = 'red', back_color = 'white')
img.save("myQR.png")

Here is the output:

myQR

I'm using Python 3.11.0 and qrcode 7.4.2

jolshin commented 3 months ago

The only option to get a QRcode with custom colors is to use color_mask=SolidFillColorMaks(back_color=(R,G,B), front_color=(R,G,B) in the way described in README.

But SolidFillColorMask() works as post-make filter and doesn't send user color set to make_image, according to the logic of this package make_image method makes QRcode in black and white by default, then gets generated QR image and changes pixel-by-pixel default (black and white) color set to custom. Such attitude takes a lot of time and resources, in my case it takes less then 0,5 seconds to generate a QR and up to 15 seconds to change colors with SolidFillColorMask()

The best way is to clone repo and make changes in make_image method (and others) so it takes custom colors if they set by user .

pwd491 commented 1 month ago

I'm also facing this issue. Here is a very minimum example where I am seeing only black and white QR codes being made:

import qrcode
qr = qrcode.QRCode(version = 1, box_size = 10, border = 4)
qr.add_data("myQR")
qr.make(fit = True)
img = qr.make_image(fill_color = 'red', back_color = 'white')
img.save("myQR.png")

Here is the output:

myQR

I'm using Python 3.11.0 and qrcode 7.4.2

Install Pillow