Closed Endogen closed 3 years ago
Thanks for the suggestion, but this isn't possible yet.
Should be easy to add, though…
I'll keep this open as an reminder to support BytesIO
Sorry, I was wrong. It is already possible:
import io
import segno
qr = segno.make('Test', error='h')
out = io.BytesIO()
qr.to_artistic(background='background.jpg', target=out, scale=10, kind='jpg')
print(out.getvalue())
Just provide the "kind" parameter.
I can't provide a URL with an image for background
right? what would i do if i don't want to save that image on disk first?
Let's say this image here: https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg
Or i would also have the BytesIO()
object of the image that i could use. But passing that to background=
doesn't seem to work
Untested but this may work:
import io
from urllib.request import urlopen
import segno
qr = segno.make('Test', error='h')
out = io.BytesIO()
url = 'https://interactive-examples.mdn.mozilla.net/media/cc0-images/grapefruit-slice-332-332.jpg'
bg_img = urlopen(url)
qr.to_artistic(background=bg_img, target=out, scale=10, kind='jpg')
print(out.getvalue())
Let me know if it doesn't work.
Unfortunately doesn't work:
AttributeError("<class 'segno.QRCode'> object has no attribute to_artistic")
The error seems to indicate that Segno cannot find the plugin.
Did you install segno and qrcode-artistic? (pip install qrcode-artistic)
Does the following work or do you get an ImportError?
import qrcode_artistic
Jesus Christ... sorry! I deinstalled it until i find out how it works to pass in the image from the URL and totally forgot to install it again for the test...
It's working now. Thanks so much for this. Helped me a lot! 👍
Thanks for your questions. I added more information regarding streams to https://segno.readthedocs.io/en/latest/artistic-qrcodes.html
Maybe you want to add this also:
b_in = io.BytesIO()
b_out = io.BytesIO()
qr = segno.make_qr("Some string")
qr.to_artistic(background=b_in, target=b_out, border=1, scale=10, kind='png')
I use that for example with a Telegram bot. I get an image asb_in
, feed it to to_artistic()
and then send a message with content of b_out
. That way i don't need to get the image myself via URL and i also don't need to temporarily save it. Love it!
Thanks for the suggestion, I added an example acc. to your suggestion. See last paragraph of https://segno.readthedocs.io/en/latest/artistic-qrcodes.html
With the main module i can do something like this:
Is there a way to do that also with artistic qr-codes?