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

[DISCUSS] Feature PR: Output as base64 #64

Open
ericmjl opened this issue Aug 13, 2018 · 4 comments
Open

[DISCUSS] Feature PR: Output as base64 #64

ericmjl opened this issue Aug 13, 2018 · 4 comments

Comments

@ericmjl
Copy link

ericmjl commented Aug 13, 2018

I wanted to discuss this feature PR before actually taking any action.

One application I wanted was to be able to take the generated QR code and display it on an HTML page, without writing anything to disk.

As it turns out, this is possible:

# mytext was created
qrcode = pq.create(mytext)
buffer = BytesIO()
qrcode.png(buffer, scale=5)
enc = b64encode(buffer.getvalue()).decode('utf-8')

I was wondering if you might be interested in accepting a PR that defines the following API?

encoding = qrcode.base64(scale=5)

The underlying implementation would essentially use the aforementioned code:

# This is a class method
def base64(self, scale=5):
    buffer = BytesIO()
    self.png(buffer, scale=scale)
    enc = b64encode(buffer.getvalue()).decode('utf-8')

Please let me know, I'm happy to work on the PR for this. Alternatively, if you're not interested in this, no hard feelings too 😄.

@heuer
Copy link
Contributor

heuer commented Aug 13, 2018

You can use:

import pyqrcode

qrcode = pyqrcode.create('Test')
encoded = qrcode.png_as_base64_str()

Note: The returned string is actually not a valid data URI. PyQRCode 1.3.0 provides QrCode.png_data_uri() which returns a data URI.

See https://github.com/heuer/pyqrcode/blob/master/CHANGES.rst
($ pip install git+https://github.com/heuer/pyqrcode.git@1.3.0)

@ericmjl
Copy link
Author

ericmjl commented Aug 13, 2018

Thanks @heuer for the information! I must have missed this, because I didn't see it in the docs. Is there a timeline for release to PyPI?

@heuer
Copy link
Contributor

heuer commented Aug 13, 2018

Is there a timeline for release to PyPI?

No, unfortunately I don't have access to the PyPI project, see issue #52

@ericmjl
Copy link
Author

ericmjl commented Aug 13, 2018

@heuer reading through the issue, just wanted to say a big thanks for being willing to take over the project. I put in a comment on pypi/warehouse#4121 to support your case for taking over pyqrcode, I hope it pushes things along.

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