Created
June 27, 2013 07:23
-
-
Save suminb/5874581 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes any arbitray data, splits it into multiple peices and encode into QR code. | |
# python-qrcode package can be obtained from https://github.com/lincolnloop/python-qrcode | |
import qrcode | |
import base64 | |
from multiprocessing import Pool | |
BLOCK_SIZE = 100 # in bytes | |
# TODO: Is it possible to get rid of these? | |
data = open("IMG_5526.jpg").read() | |
n = len(data) | |
def gen(seq, data): | |
qr = qrcode.QRCode( | |
version=1, | |
error_correction=qrcode.constants.ERROR_CORRECT_L, | |
box_size=8, | |
border=1, | |
) | |
qr.add_data(data) | |
qr.make(fit=True) | |
img = qr.make_image() | |
print 'Generating %05d.png' % seq | |
img.save('qrcode-output/%05d.png' % seq) | |
def seq(i): | |
# Lower bound (inclusive) and upper bound (exclusive) | |
lb, ub = i*BLOCK_SIZE, min((i+1)*BLOCK_SIZE, n) | |
gen(i, data[lb:ub]) | |
def main(): | |
seqs = range(0, n/BLOCK_SIZE+1) | |
pool = Pool(processes=4) | |
pool.map(seq, seqs) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment