Skip to content
Open
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
5 changes: 5 additions & 0 deletions desktop-tool/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,8 @@ class TargetSites(Enum):
THREADS = 5 # shared between CardImageCollections

POST_LAUNCH_HTML_FILENAME = "post-launch.html"

# Card physical dimensions for border calculation
CARD_WIDTH_INCHES = 2.5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
CARD_WIDTH_INCHES = 2.5
CARD_WIDTH_INCHES = 2.48
CARD_HEIGHT_INCHES = 3.46
BORDER_INCHES = 0.12

these are the actual values that MPC uses (or at least a bit closer)

CARD_HEIGHT_INCHES = 3.5
BORDER_INCHES = 0.125
28 changes: 28 additions & 0 deletions desktop-tool/src/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,32 @@ def download_google_drive_file(
return True


def download_image_from_url(
url: str, file_path: str, post_processing_config: Optional[ImagePostProcessingConfig]
) -> bool:
"""
Download an image from a URL to the specified `file_path`.
Returns whether the request was successful or not.
"""
logging.debug(f"Downloading image from {url}...")
try:
response = requests.get(url)
response.raise_for_status()
file_bytes = response.content
except requests.exceptions.RequestException as e:
logging.error(f"Encountered an error while downloading image from {url}: {e}")
return False

if post_processing_config is not None:
logging.debug(f"Post-processing image from {url}...")
processed_image = post_process_image(raw_image=file_bytes, config=post_processing_config)
processed_image.save(file_path)
else:
# Save the bytes directly to disk
with open(file_path, "wb") as f:
f.write(file_bytes)
logging.debug(f"Finished downloading image from {url}!")
return True


# endregion
Loading