Created
June 3, 2015 09:30
-
-
Save Lukasa/63cdeb6b8229755c6b96 to your computer and use it in GitHub Desktop.
Generate images of GPG signatures
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
import getpass | |
import gnupg | |
from PIL import Image, ImageFont, ImageDraw | |
g = gnupg.GPG() | |
data = raw_input('Tweet: ') | |
passphrase = getpass.getpass('Passphrase: ') | |
signature = str(g.sign(data, passphrase=passphrase, clearsign=False)) | |
image = Image.new('RGB', (10000, 10000)) | |
draw = ImageDraw.Draw(image) | |
font = ImageFont.truetype('Inconsolata-Regular.ttf', size=24) | |
height = 5 | |
max_width = 0 | |
size = (0, 0) | |
for line in signature.splitlines(): | |
# Leave a space for blank lines. | |
if not line: | |
height += size[1] | |
pass | |
size = font.getsize(line) | |
draw.text((5, height), line, font=font) | |
height += size[1] | |
max_width = max(max_width, size[0] + 10) | |
image = image.crop((0, 0, max_width, height + 10)) | |
image.save('test.jpg', 'JPEG') | |
print signature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment