|
| 1 | +from PIL import Image, ImageDraw, ImageFont |
| 2 | +import qrcode |
| 3 | + |
| 4 | + |
| 5 | +def makeQR(string): |
| 6 | + """ |
| 7 | + Makes a QRcode image from <string> |
| 8 | + """ |
| 9 | + qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=4, border=1,) |
| 10 | + qr.add_data(string) |
| 11 | + qr.make(fit=True) |
| 12 | + qrim = qr.make_image() |
| 13 | + return qrim.convert('RGBA') |
| 14 | + |
| 15 | +def makePaper(publickey, privatekey, background='paperwallet.png', fontsize=10, font='/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf'): |
| 16 | + # Open the paperwallet background |
| 17 | + r = Image.open(background).convert('RGBA') |
| 18 | + # Make and Paste QrCodes |
| 19 | + r.paste(makeQR(publickey),(20,20)) |
| 20 | + r.paste(makeQR(privatekey),(560,135)) |
| 21 | + # Rotate base -90 degrees |
| 22 | + base = r.rotate(-90) |
| 23 | + # Make blank transparent image for text |
| 24 | + txt = Image.new('RGBA', base.size, (160,160,160,0)) |
| 25 | + # Set the Font of text |
| 26 | + fnt = ImageFont.truetype(font, fontsize) |
| 27 | + # Draw the addresses on the new image |
| 28 | + d = ImageDraw.Draw(txt) |
| 29 | + d.text((15,172), publickey, font=fnt, fill=(0,0,0,250)) |
| 30 | + d.text((15,537), privatekey, font=fnt, fill=(0,0,0,250)) |
| 31 | + |
| 32 | + # Merge the 2 layers and rotate -90 degrees |
| 33 | + out = Image.alpha_composite(base, txt) |
| 34 | + out.rotate(90).show() |
| 35 | + |
| 36 | +if __name__ == "__main__": |
| 37 | + import sys |
| 38 | + if not len(sys.argv) > 2: |
| 39 | + print("At least 2 Arguments are required: <publickey> <privatekey> [image] [fontsize] [font]") |
| 40 | + sys.exit() |
| 41 | + pubkey=sys.argv[1] |
| 42 | + privkey=sys.argv[2] |
| 43 | + if not len(sys.argv) > 3: makePaper(pubkey, privkey) |
| 44 | + if not len(sys.argv) > 4: makePaper(pubkey, privkey, sys.argv[3]) |
| 45 | + if not len(sys.argv) > 5: makePaper(pubkey, privkey, sys.argv[3], int(sys.argv[4])) |
| 46 | + else:makePaper(pubkey, privkey, sys.argv[3], int(sys.argv[4]), sys.argv[5]) |
0 commit comments