Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'SvgPathImage' object has no attribute 'mode' #356

Open
nabelekt opened this issue Feb 17, 2024 · 2 comments
Open

AttributeError: 'SvgPathImage' object has no attribute 'mode' #356

nabelekt opened this issue Feb 17, 2024 · 2 comments

Comments

@nabelekt
Copy link

nabelekt commented Feb 17, 2024

I am just learning how to use this python module, so I may not be using it as intended, but it does seem like some error is not being handled appropriately. Here's my code:

import qrcode
import qrcode.image.svg

# Documentation: https://github.com/lincolnloop/python-qrcode
qr = qrcode.QRCode(
    version=None,  # Controls size of QR code
    error_correction=qrcode.constants.ERROR_CORRECT_M,  # Error correction level
    box_size=10,  # How many pixels per box
    border=4,  # Border size; min is 10 per spec
)

qr.add_data("something interesting")
qr.make(fit=True)

factory = factory = qrcode.image.svg.SvgPathImage
img = qr.make_image(image_factory=factory,
                    fill_color="black",
                    back_color="white",
                    module_drawer=qrcode.image.styles.moduledrawers.HorizontalBarsDrawer())

Here's the error I am getting:

Traceback (most recent call last):
  File "/home/thomas/repos/utilities/commissioning/qr_test.py", line 22, in <module>
    img = qr.make_image(image_factory=factory,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/main.py", line 365, in make_image
    im = image_factory(
         ^^^^^^^^^^^^^^
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/svg.py", line 145, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/svg.py", line 27, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 139, in __init__
    super().__init__(*args, **kwargs)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 31, in __init__
    self.init_new_image()
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/base.py", line 150, in init_new_image
    self.module_drawer.initialize(img=self)
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/styles/moduledrawers/pil.py", line 232, in initialize
    self.setup_edges()
  File "/home/thomas/.local/lib/python3.11/site-packages/qrcode/image/styles/moduledrawers/pil.py", line 235, in setup_edges
    mode = self.img.mode
           ^^^^^^^^^^^^^
AttributeError: 'SvgPathImage' object has no attribute 'mode'

Thanks!

@WillPoulson
Copy link

Also getting the same error here when trying to follow the docs. Did you find a solution?

@nabelekt
Copy link
Author

nabelekt commented Nov 4, 2024

Looking at the code I use now, this is what I have:

...
    qr.add_data(data_string)
    qr.make(fit=True)

    img = qr.make_image(image_factory=StyledPilImage,
                        fill_color="black",
                        back_color="white",
                        # module_drawer=qrcode.image.styles.moduledrawers.GappedSquareModuleDrawer(),
                        module_drawer=qrcode.image.styles.moduledrawers.HorizontalBarsDrawer(),
                        embeded_image_path=path_to_logo_file)
...

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants