Skip to content

Instantly share code, notes, and snippets.

@Lukasa
Created June 3, 2015 09:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lukasa/63cdeb6b8229755c6b96 to your computer and use it in GitHub Desktop.
Save Lukasa/63cdeb6b8229755c6b96 to your computer and use it in GitHub Desktop.
Generate images of GPG signatures
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