Skip to content

Commit

Permalink
utils.functions:image_size - use imagesize to get image size
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoCampinoti94 committed Jun 21, 2024
1 parent fb3fa73 commit 0dd300a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions acacore/utils/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Generator
from typing import TypeVar

from PIL import Image
from imagesize import get as get_image_size

T = TypeVar("T")
R = TypeVar("R")
Expand Down Expand Up @@ -119,11 +119,12 @@ def image_size(path: Path) -> tuple[int, int]:
"""
Calculate the size of an image.
Supports PNG, JPEG, JPEG2000, GIF, TIFF, SVG, Netpbm, WebP.
:param path: The path to the image file.
:raises FileNotFoundError: If the provided path does not exist.
:raises IsADirectoryError: If the provided path points to a directory instead of a file.
:raises PIL.UnidentifiedImageError: If the provided file is not a valid image file.
:raises ValueError: If the provided file is not a valid image file.
:return: A tuple representing the width and height of the image.
"""
with Image.open(path) as i:
return i.size
return get_image_size(path)

0 comments on commit 0dd300a

Please sign in to comment.