Updated requirements and license, fixed a bug introduced with new pillow version.

This commit is contained in:
Jeremy Karst 2025-01-14 13:19:07 -05:00
parent c1c65cac4f
commit ddb6679b63
6 changed files with 36 additions and 21 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.venv/
signatures.db
__pycache__/
*.pyc

View file

@ -1,12 +1,20 @@
# Written by Jeremy Karst 2025
# This software is licensed under the MIT License with Additional Terms.
# See LICENSE.md for more information.
# Built-in Dependencies
import time
import requests
import statistics
from concurrent.futures import ThreadPoolExecutor
import argparse
import random
# External Dependencies
import requests
from rich.console import Console
from rich.table import Table
from rich.progress import Progress
import random
def make_request(base_url, session):
"""Make requests to test the full signature flow"""

View file

@ -5,7 +5,7 @@ services:
context: .
dockerfile: osg.dockerfile
image: osg:20 # <--automate this number change to trigger stack redeploy.
image: osg:21 # <--automate this number change to trigger stack redeploy.
environment:
DOCKER: "true"

View file

@ -1,6 +1,8 @@
CherryPy==18.9.0
cryptography==42.0.5
fonttools==4.50.0
CherryPy==18.10.0
cryptography==44.0.0
fonttools==4.55.3
geocoder==1.38.1
pillow==10.2.0
qrcode==8.0
pillow==11.1.0
qrcode==8.0
requests==2.32.3
rich==13.9.4

View file

@ -1,3 +1,8 @@
# Written by Jeremy Karst 2025
# This software is licensed under the MIT License with Additional Terms.
# See LICENSE.md for more information.
# Built-in Dependencies
import os
import sqlite3
import time
@ -12,11 +17,13 @@ from threading import Timer
import multiprocessing
from multiprocessing import Pool
# External Dependencies
import cherrypy
from cherrypy.lib import file_generator
from fontTools import ttLib
import geocoder
# Local Dependencies
from sha_sign import hash_text, generate_signature_image

View file

@ -1,21 +1,18 @@
# Written by Jeremy Karst 2025
# This software is licensed under the MIT License with Additional Terms.
# See LICENSE.md for more information.
# Built-in Dependencies
import base64
import time
import datetime
try:
import cryptography
import qrcode
import PIL
import pytz
except ImportError:
import pip
pip.main(['install', 'cryptography', 'qrcode', 'Pillow'])
# External Dependencies
from cryptography.hazmat.primitives import hashes
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.moduledrawers.pil import CircleModuleDrawer
from qrcode.image.styles.colormasks import RadialGradiantColorMask
from qrcode.image.styles.colormasks import RadialGradiantColorMask, SolidFillColorMask
from PIL import Image, ImageDraw, ImageFont
def hash_text(text: str) -> str:
@ -58,7 +55,7 @@ def generate_signature_image(sig_name: str, sig_time: int, sig_timezone: datetim
if gradient:
qr_img = qr.make_image(fit=True, image_factory=StyledPilImage, module_drawer=CircleModuleDrawer(), color_mask=RadialGradiantColorMask(back_color=(0, 0, 0, 128), center_color=(245, 245, 245, 255), edge_color=(250, 250, 250, 255)))
else:
qr_img = qr.make_image(fit=True, image_factory=StyledPilImage, module_drawer=CircleModuleDrawer())
qr_img = qr.make_image(fit=True, image_factory=StyledPilImage, module_drawer=CircleModuleDrawer(), color_mask=SolidFillColorMask(back_color=(0, 0, 0, 128), front_color=(250, 250, 250, 255)))
else:
if gradient:
qr_img = qr.make_image(fit=True, image_factory=StyledPilImage, module_drawer=CircleModuleDrawer(), color_mask=RadialGradiantColorMask(back_color=(255, 255, 255, 128), center_color=(10, 10, 150, 255), edge_color=(5, 5, 20, 255)))
@ -99,7 +96,7 @@ def generate_signature_image(sig_name: str, sig_time: int, sig_timezone: datetim
draw = ImageDraw.Draw(image)
draw.text((padding - sig_bbox[0], v_anchor), sig_name, font=sig_font, fill=sig_color, anchor="ls")
draw.text((padding + sig_width + interspacing - note_bbox[0], v_anchor - note_bbox[3]), note_text, font=sans_font, fill=note_color, anchor="ls")
image.paste(qr_img, (padding + sig_width + interspacing + note_width + interspacing, v_anchor - qr_size))
image.paste(qr_img._img, (padding + sig_width + interspacing + note_width + interspacing, v_anchor - qr_size))
# final_time = time.perf_counter()
@ -127,6 +124,6 @@ if __name__ == "__main__":
signature_data = f"osg.jkdev.org/v/{hash_id}"
image = generate_signature_image(sig_name, timestamp, timezone, signature_data, sig_font_path, note_font_path, invert_colors=False, gradient=True)
image = generate_signature_image(sig_name, timestamp, timezone, signature_data, sig_font_path, note_font_path, invert_colors=True, gradient=True)
image.save(f"Signature {hash_id} {timestamp}.png", optimize=True, compress_level=9)