Visitar URL original
`fill_color` and `back_color` not working. · Issue #324 · lincolnloop/python-qrcode · GitHub
Skip to content

fill_color and back_color not working. #324

Description

@Liscuri

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.

Activity

  1. lucashahnndev commented on Jul 11, 2023

    @lucashahnndev

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

  2. kake-r commented on Jul 29, 2023

    @kake-r

    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
    
  3. IS0metric commented on Sep 4, 2023

    @IS0metric

    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

  4. jolshin commented on Mar 13, 2024

    @jolshin

    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 .

  5. rootcreep commented on May 16, 2024

    @rootcreep

    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

  6. ToshY commented on Oct 9, 2025

    @ToshY

    I just bumped into this. This is very counter-intuitive; using PilImage works, but StyledPilImage doesn't. Common naming convention rules had me fooled that StyledPilImage would be an extension of PilImage, but it appears to have different use cases.

    TLDR

    • use PilImage when you want to use fill_color and back_color (which is the default if None is given to make_image).
    • use StyledPilImage when you want to use color_mask (with SolidFillColorMask).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions