Skip to content

Commit

Permalink
fix(thumbnail, generation): now can use the thumbnail generation with…
Browse files Browse the repository at this point in the history
… only the width GET arg
  • Loading branch information
jacquesfize committed Dec 20, 2024
1 parent ab680d7 commit 34829e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion apptax/taxonomie/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ def create_thumb(self, media, size, force=False, regenerate=False):

# Get Image
try:
img = self._get_image_object(media)
img: Image = self._get_image_object(media)

Check warning on line 97 in apptax/taxonomie/filemanager.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/filemanager.py#L97

Added line #L97 was not covered by tests
except TaxhubError as e:
return None

# If width only was given in the parameter (height <=> size[1] < 0)
if size[1] < 0:
size[1] = img.width / size[0] * img.height

Check warning on line 103 in apptax/taxonomie/filemanager.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/filemanager.py#L102-L103

Added lines #L102 - L103 were not covered by tests

# Création du thumbnail
resizeImg = resize_thumbnail(img, (size[0], size[1], force))
# Sauvegarde de l'image
Expand Down
15 changes: 12 additions & 3 deletions apptax/taxonomie/routestmedias.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from .filemanager import FILEMANAGER

DEFAULT_THUMBNAIL_SIZE = (300, 400)

adresses = Blueprint("t_media", __name__)
logger = logging.getLogger()
Expand Down Expand Up @@ -84,9 +85,17 @@ def getThumbnail_tmedias(id_media):
)

params = request.args
size = (300, 400)
if ("h" in params) or ("w" in params):
size = (int(params.get("h", -1)), int(params.get("w", -1)))

size = DEFAULT_THUMBNAIL_SIZE

Check warning on line 89 in apptax/taxonomie/routestmedias.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/routestmedias.py#L89

Added line #L89 was not covered by tests

height_params: str = params.get("h", "-1")
width_params: str = params.get("w", "-1")

Check warning on line 92 in apptax/taxonomie/routestmedias.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/routestmedias.py#L91-L92

Added lines #L91 - L92 were not covered by tests

if width_params and width_params.isdigit():
size = (int(width_params), size[1])

Check warning on line 95 in apptax/taxonomie/routestmedias.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/routestmedias.py#L94-L95

Added lines #L94 - L95 were not covered by tests

if height_params and height_params.isdigit():
size = (size[0], int(height_params))

Check warning on line 98 in apptax/taxonomie/routestmedias.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/routestmedias.py#L97-L98

Added lines #L97 - L98 were not covered by tests

force = False
if ("force" in params) and (params.get("force") == "true"):
Expand Down

0 comments on commit 34829e0

Please sign in to comment.