From ddb6679b63b4bcdd5c349dc7a34b0be730317b0e Mon Sep 17 00:00:00 2001 From: Jeremy Karst Date: Tue, 14 Jan 2025 13:19:07 -0500 Subject: [PATCH] Updated requirements and license, fixed a bug introduced with new pillow version. --- .gitignore | 1 + benchmark.py | 12 ++++++++++-- compose.yaml | 2 +- requirements.txt | 12 +++++++----- server.py | 7 +++++++ sha_sign.py | 23 ++++++++++------------- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index eb10d1b..bcf14f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.venv/ signatures.db __pycache__/ *.pyc diff --git a/benchmark.py b/benchmark.py index eced928..71e03bd 100644 --- a/benchmark.py +++ b/benchmark.py @@ -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""" diff --git a/compose.yaml b/compose.yaml index 4db781f..8a17f96 100644 --- a/compose.yaml +++ b/compose.yaml @@ -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" diff --git a/requirements.txt b/requirements.txt index 1539323..70fa40b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file +pillow==11.1.0 +qrcode==8.0 +requests==2.32.3 +rich==13.9.4 \ No newline at end of file diff --git a/server.py b/server.py index 1271b3f..92f8636 100644 --- a/server.py +++ b/server.py @@ -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 diff --git a/sha_sign.py b/sha_sign.py index 284dd7f..0134c07 100644 --- a/sha_sign.py +++ b/sha_sign.py @@ -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) \ No newline at end of file