mnooner256 / pyqrcode

Python 3 module to generate QR Codes
BSD 3-Clause "New" or "Revised" License
408 stars 74 forks source link

[DISCUSS] Feature PR: Output as base64 #64

Open ericmjl opened 5 years ago

ericmjl commented 5 years ago

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 :smile:.

heuer commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

Is there a timeline for release to PyPI?

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

ericmjl commented 5 years ago

@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 https://github.com/pypa/warehouse/issues/4121 to support your case for taking over pyqrcode, I hope it pushes things along.