Skip to content

[MDS-3871] - update esup permit template with inspector name #2758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import base64
from io import BytesIO

from PIL import Image
from flask import current_app
from sqlalchemy.schema import FetchedValue

Expand Down Expand Up @@ -48,6 +52,27 @@ def validate_issuing_inspector(explosives_permit):
raise Exception('No signature for the Issuing Inspector has been provided')

def create_image(source, width=None, height=None):

# If there is a prefix in the source, remove it
base64_source = source
Copy link
Collaborator

@asinn134 asinn134 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work with this part

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, took a bit of figuring to get it working just right.

if ';base64,' in base64_source:
prefix, base64_source = base64_source.split(';base64,', 1)

# Convert base64 string to PIL Image to get dimensions
img_data = base64.b64decode(base64_source)
img = Image.open(BytesIO(img_data))

# Use aspect ratio of image to calculate width if not provided
if height and not width:
aspect_ratio = img.width / img.height
# Convert height from inches to pixels (Word assumes 96 DPI)
height_in_pixels = height * 96

# Calculate width while maintaining aspect ratio
width = height_in_pixels * aspect_ratio
# Convert width from pixels back to inches
width = width / 96

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 🤓

return {'source': source, 'width': width, 'height': height}

is_draft = template_data.get('is_draft', True)
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion services/core-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ opentelemetry-instrumentation-flask==0.33b0
opentelemetry-instrumentation-redis==0.33b0
opentelemetry-instrumentation-requests==0.33b0
opentelemetry-instrumentation-sqlalchemy==0.33b0
opentelemetry-instrumentation-urllib3==0.33b0
opentelemetry-instrumentation-urllib3==0.33b0
Pillow==8.4.0
Loading