Repository navigation
fill_color and back_color not working. #324
Description
Activity
I also noticed that it doesn't work if I use
"image_factory=StyledPilImage" apart from that "fill_color" and "back_color" WORKS NORMALLY!Reacted by ResoI'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.2I'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:
I'm using Python 3.11.0 and qrcode 7.4.2
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 tomake_image, according to the logic of this packagemake_imagemethod 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 withSolidFillColorMask()The best way is to clone repo and make changes in
make_imagemethod (and others) so it takes custom colors if they set by user .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:
I'm using Python 3.11.0 and qrcode 7.4.2
Install Pillow
Reacted by Michael DeuchertReacted by ToshY and twistedturtleI just bumped into this. This is very counter-intuitive; using
PilImageworks, butStyledPilImagedoesn't. Common naming convention rules had me fooled thatStyledPilImagewould be an extension ofPilImage, but it appears to have different use cases.TLDR
- use
PilImagewhen you want to usefill_colorandback_color(which is the default ifNoneis given tomake_image). - use
StyledPilImagewhen you want to usecolor_mask(withSolidFillColorMask).
Reacted by twistedturtle- use


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.