Skip to content

Commit

Permalink
Added check, if resized folder exists, and create it if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianH99 committed Jul 28, 2024
1 parent 68fd987 commit e781e1e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docs/_build/*
docs/source/_ext/__pycache__
/.vscode
/docs/source/_static/images/resized
/docs/source/_static/images/resized/*
14 changes: 8 additions & 6 deletions docs/source/_ext/populate_team_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,22 @@ def get_team_country(team_name, data):
return None

def resize_image(abs_input_image_path, abs_output_image_path, new_height):
if abs_input_image_path.endswith(('.png', '.jpg', '.jpeg', '.PNG', '.JPG', '.JPEG')):
print(f"Open image from path {abs_input_image_path}")
if abs_input_image_path.endswith(('.png', '.jpg', '.jpeg', '.PNG', '.JPG', '.JPEG')) and os.path.exists(abs_input_image_path):
img = Image.open(abs_input_image_path)
aspect_ratio = img.width / img.height
new_width = int(new_height * aspect_ratio)
print("Resizing image")
img = img.resize((new_width, new_height), Image.Resampling.LANCZOS)

print("Saving image")
img.save(abs_output_image_path)
abs_output_image_dir, x = os.path.split(abs_output_image_path)

if not os.path.exists(abs_output_image_dir):
print("resized folder missing. Creating it.")
os.mkdir(abs_output_image_dir)

img.save(abs_output_image_path)
return abs_output_image_path
else:
print(f"File provided for resize_image is in wrong format. (Filepath: {abs_input_image_path})")
print(f"File provided for resize_image is in wrong format or not available. (Filepath: {abs_input_image_path})")
return None

def setup(app):
Expand Down

0 comments on commit e781e1e

Please sign in to comment.