lincolnloop / python-qrcode

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

only black colored qr code with image_factory = qrcode.image.svg.SvgPathImage #339

Closed tusharmehta3 closed 11 months ago

tusharmehta3 commented 11 months ago

fill_color and back_color is not changing the color of the qr code. Below is the code I'm using to generate the qr code.

import qrcode
import qrcode.image.svg

QRcode = qrcode.QRCode(
            version=8, # controls the size of the QR Code.
            error_correction=qrcode.constants.ERROR_CORRECT_H,
            box_size=9, # controls how many pixels each "box" of the QR code is.
            border=3)

QRcode.add_data('https') # Adds the data to the QR code
QRcode.make() 

QRimg = QRcode.make_image(color= '#FF0000', fill_color='#008000', image_factory= qrcode.image.svg.SvgPathImage)

QRimg = QRimg.to_string().decode()

with open('output.svg', 'w') as f:
        f.write(QRimg)
tusharmehta3 commented 11 months ago

UPDATE: I changed the color of the qr code with the following command qrcode.image.svg.SvgPathImage.QR_PATH_STYLE["fill"] = "#ff0000"

But how can the background color be changed?

tusharmehta3 commented 11 months ago

UPDATE 2: Managed to change the background color with the following command:

qrcode.image.svg.SvgPathImage.QR_PATH_STYLE["stroke"] = "#008000"
qrcode.image.svg.SvgPathImage.QR_PATH_STYLE["stroke-opacity"] = "0.2"
qrcode.image.svg.SvgPathImage.QR_PATH_STYLE["stroke-width"] = "5.5"

defining 'stroke-opacity' because it changes the color of the whole image instead of the white background & 'stroke-width' to fill the whole image

tusharmehta3 commented 11 months ago

Is it possible to fill only the white area instead of using stroke-opacity and stroke-width?