Updated requirements and license, fixed a bug introduced with new pillow version.
This commit is contained in:
parent
c1c65cac4f
commit
ddb6679b63
6 changed files with 36 additions and 21 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
.venv/
|
||||||
signatures.db
|
signatures.db
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
12
benchmark.py
12
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 time
|
||||||
import requests
|
|
||||||
import statistics
|
import statistics
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
import argparse
|
import argparse
|
||||||
|
import random
|
||||||
|
|
||||||
|
# External Dependencies
|
||||||
|
import requests
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.progress import Progress
|
from rich.progress import Progress
|
||||||
import random
|
|
||||||
|
|
||||||
def make_request(base_url, session):
|
def make_request(base_url, session):
|
||||||
"""Make requests to test the full signature flow"""
|
"""Make requests to test the full signature flow"""
|
||||||
|
|
|
@ -5,7 +5,7 @@ services:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: osg.dockerfile
|
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:
|
environment:
|
||||||
DOCKER: "true"
|
DOCKER: "true"
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
CherryPy==18.9.0
|
CherryPy==18.10.0
|
||||||
cryptography==42.0.5
|
cryptography==44.0.0
|
||||||
fonttools==4.50.0
|
fonttools==4.55.3
|
||||||
geocoder==1.38.1
|
geocoder==1.38.1
|
||||||
pillow==10.2.0
|
pillow==11.1.0
|
||||||
qrcode==8.0
|
qrcode==8.0
|
||||||
|
requests==2.32.3
|
||||||
|
rich==13.9.4
|
|
@ -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 os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
@ -12,11 +17,13 @@ from threading import Timer
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool
|
||||||
|
|
||||||
|
# External Dependencies
|
||||||
import cherrypy
|
import cherrypy
|
||||||
from cherrypy.lib import file_generator
|
from cherrypy.lib import file_generator
|
||||||
from fontTools import ttLib
|
from fontTools import ttLib
|
||||||
import geocoder
|
import geocoder
|
||||||
|
|
||||||
|
# Local Dependencies
|
||||||
from sha_sign import hash_text, generate_signature_image
|
from sha_sign import hash_text, generate_signature_image
|
||||||
|
|
||||||
|
|
||||||
|
|
23
sha_sign.py
23
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 base64
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
try:
|
# External Dependencies
|
||||||
import cryptography
|
|
||||||
import qrcode
|
|
||||||
import PIL
|
|
||||||
import pytz
|
|
||||||
except ImportError:
|
|
||||||
import pip
|
|
||||||
pip.main(['install', 'cryptography', 'qrcode', 'Pillow'])
|
|
||||||
|
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
import qrcode
|
import qrcode
|
||||||
from qrcode.image.styledpil import StyledPilImage
|
from qrcode.image.styledpil import StyledPilImage
|
||||||
from qrcode.image.styles.moduledrawers.pil import CircleModuleDrawer
|
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
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
def hash_text(text: str) -> str:
|
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:
|
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)))
|
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:
|
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:
|
else:
|
||||||
if gradient:
|
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)))
|
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 = 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_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")
|
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()
|
# final_time = time.perf_counter()
|
||||||
|
|
||||||
|
@ -127,6 +124,6 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
signature_data = f"osg.jkdev.org/v/{hash_id}"
|
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)
|
image.save(f"Signature {hash_id} {timestamp}.png", optimize=True, compress_level=9)
|
Loading…
Reference in a new issue