qrencode-1.01/0000755016505700116100000000000011127407576012440 5ustar nickjohnsonqrencode-1.01/PKG-INFO0000644016505700116100000000127511127407576013542 0ustar nickjohnsonMetadata-Version: 1.1 Name: qrencode Version: 1.01 Summary: Encodes QR-codes. Home-page: http://github.com/Arachnid/pyqrencode/tree/master Author: Nick Johnson Author-email: arachnid@notdot.net License: http://www.apache.org/licenses/LICENSE-2.0 Description: A simple wrapper for the C qrencode library. Platform: any Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Apache Software License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Multimedia :: Graphics Classifier: Topic :: Printing Classifier: Topic :: Software Development :: Libraries Requires: PIL qrencode-1.01/._qr_encode.c0000644016505700116100000000025311127402445014746 0ustar nickjohnsonMac OS X  2y«ATTR B髜œcom.apple.TextEncodingUTF-8;134217984qrencode-1.01/qr_encode.c0000644016505700116100000000207511127402445014535 0ustar nickjohnson#include #include #include static PyObject *qr_encode(PyObject *self, PyObject *args) { char *str; int i, version, level, hint, case_sensitive, num_pixels; QRcode *code; PyObject *ret; if(!PyArg_ParseTuple(args, "siiii", &str, &version, &level, &hint, &case_sensitive)) return NULL; code = QRcode_encodeString(str, version, level, hint, case_sensitive); num_pixels = code->width * code->width; for(i = 0; i < num_pixels; i++) code->data[i] = 255 - (code->data[i] & 0x1) * 0xFF; ret = Py_BuildValue("(iis#)", code->version, code->width, code->data, num_pixels); QRcode_free(code); return ret; }; static PyMethodDef qr_encode_methods[] = { {"encode", qr_encode, METH_VARARGS, "Encodes a string as a QR-code. Returns a tuple of (version, width, data)"}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initqr_encode(void) { PyObject *m = Py_InitModule("qr_encode", qr_encode_methods); if(m == NULL) return; } qrencode-1.01/qrencode/0000755016505700116100000000000011127407576014240 5ustar nickjohnsonqrencode-1.01/qrencode/.___init__.py0000644016505700116100000000025311127405114016550 0ustar nickjohnsonMac OS X  2y«ATTR CK«œœcom.apple.TextEncodingUTF-8;134217984qrencode-1.01/qrencode/__init__.py0000644016505700116100000000566511127405114016347 0ustar nickjohnsonfrom qr_encode import encode as _encode import Image QR_ECLEVEL_L = 0 QR_ECLEVEL_M = 1 QR_ECLEVEL_Q = 2 QR_ECLEVEL_H = 3 levels = [QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_Q, QR_ECLEVEL_H] QR_MODE_8 = 2 QR_MODE_KANJI = 3 hints = [QR_MODE_8, QR_MODE_KANJI] def encode(data, version=0, level=QR_ECLEVEL_L, hint=QR_MODE_8, case_sensitive=True): """Creates a QR-Code from string data. Args: data: string: The data to encode in a QR-code. If a unicode string is supplied, it will be encoded in UTF-8. version: int: The minimum version to use. If set to 0, the library picks the smallest version that the data fits in. level: int: Error correction level. Defaults to 'L'. hint: int: The type of data to encode. Either QR_MODE_8 or QR_MODE_KANJI. case_sensitive: bool: Should string data be encoded case-preserving? Returns: A (version, size, image) tuple, where image is a size*size PIL image of the QR-code. """ if isinstance(data, unicode): data = data.encode('utf8') elif not isinstance(data, basestring): raise ValueError('data argument must be a string.') version = int(version) if level not in levels: raise ValueError('Invalid error-correction level.') if hint not in hints: raise ValueError('Invalid encoding mode.') if case_sensitive: version, size, data = _encode(data, version, level, hint, True) else: version, size, data = _encode(data, version, level, hint, False) im = Image.fromstring('L', (size, size), data) return (version, size, im) def encode_scaled(data, size, version=0, level=QR_ECLEVEL_L, hint=QR_MODE_8, case_sensitive=True): """Creates a QR-code from string data, resized to the specified dimensions. Args: data: string: The data to encode in a QR-code. If a unicode string is supplied, it will be encoded in UTF-8. size: int: Output size. If this is not an exact multiple of the QR-code's dimensions, padding will be added. If this is smaller than the QR-code's dimensions, it is ignored. version: int: The minimum version to use. If set to 0, the library picks the smallest version that the data fits in. level: int: Error correction level. Defaults to 'L'. hint: int: The type of data to encode. Either QR_MODE_8 or QR_MODE_KANJI. case_sensitive: bool: Should string data be encoded case-preserving? Returns: A (version, size, image) tuple, where image is a size*size PIL image of the QR-code. """ version, src_size, im = encode(data, version, level, hint, case_sensitive) if size < src_size: size = src_size qr_size = (size / src_size) * src_size im = im.resize((qr_size, qr_size), Image.NEAREST) pad = (size - qr_size) / 2 ret = Image.new("L", (size, size), 255) ret.paste(im, (pad, pad)) return (version, size, ret) qrencode-1.01/._setup.py0000644016505700116100000000025311127407575014366 0ustar nickjohnsonMac OS X  2y«ATTR D£«œœcom.apple.TextEncodingUTF-8;134217984qrencode-1.01/setup.py0000644016505700116100000000165311127407575014156 0ustar nickjohnsonfrom distutils.core import setup, Extension encode = Extension('qr_encode', sources=['qr_encode.c'], libraries=['qrencode']) classifiers = """ Development Status :: 4 - Beta Intended Audience :: Developers License :: OSI Approved :: Apache Software License Operating System :: OS Independent Programming Language :: Python Topic :: Multimedia :: Graphics Topic :: Printing Topic :: Software Development :: Libraries """ setup(name='qrencode', version='1.01', description='Encodes QR-codes.', author='Nick Johnson', author_email='arachnid@notdot.net', url='http://github.com/Arachnid/pyqrencode/tree/master', long_description='''A simple wrapper for the C qrencode library.''', packages=['qrencode'], ext_modules=[encode], requires=['PIL'], license='http://www.apache.org/licenses/LICENSE-2.0', platforms=['any'], classifiers=filter(None, classifiers.split('\n')))