stouputils 1.2.14__tar.gz → 1.2.16__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {stouputils-1.2.14 → stouputils-1.2.16}/PKG-INFO +4 -1
  2. {stouputils-1.2.14 → stouputils-1.2.16}/pyproject.toml +4 -1
  3. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/image.py +32 -17
  4. {stouputils-1.2.14 → stouputils-1.2.16}/.gitignore +0 -0
  5. {stouputils-1.2.14 → stouputils-1.2.16}/LICENSE +0 -0
  6. {stouputils-1.2.14 → stouputils-1.2.16}/README.md +0 -0
  7. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/__init__.py +0 -0
  8. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/all_doctests.py +0 -0
  9. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/applications/__init__.py +0 -0
  10. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/applications/automatic_docs.py +0 -0
  11. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/archive.py +0 -0
  12. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/backup.py +0 -0
  13. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/collections.py +0 -0
  14. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/continuous_delivery/__init__.py +0 -0
  15. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/continuous_delivery/cd_utils.py +0 -0
  16. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/continuous_delivery/github.py +0 -0
  17. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/continuous_delivery/pypi.py +0 -0
  18. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/continuous_delivery/pyproject.py +0 -0
  19. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/ctx.py +0 -0
  20. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/decorators.py +0 -0
  21. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/dont_look/zip_file_override.py +0 -0
  22. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/io.py +0 -0
  23. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/parallel.py +0 -0
  24. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/print.py +0 -0
  25. {stouputils-1.2.14 → stouputils-1.2.16}/stouputils/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stouputils
3
- Version: 1.2.14
3
+ Version: 1.2.16
4
4
  Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
5
5
  Project-URL: Homepage, https://github.com/Stoupy51/stouputils
6
6
  Project-URL: Issues, https://github.com/Stoupy51/stouputils/issues
@@ -14,6 +14,9 @@ Requires-Dist: furo>=2024.8.6
14
14
  Requires-Dist: hatch>=1.14.0
15
15
  Requires-Dist: m2r2>=0.3.3.post2
16
16
  Requires-Dist: myst-parser>=4.0.1
17
+ Requires-Dist: numpy>=2.2.4
18
+ Requires-Dist: opencv-python>=4.8.1.78
19
+ Requires-Dist: pillow>=11.1.0
17
20
  Requires-Dist: pyyaml>=6.0.0
18
21
  Requires-Dist: requests>=2.30.0
19
22
  Requires-Dist: sphinx-rtd-theme>=3.0.2
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
 
6
6
  [project]
7
7
  name = "stouputils"
8
- version = "1.2.14"
8
+ version = "1.2.16"
9
9
  description = "Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more."
10
10
  readme = "README.md"
11
11
  requires-python = ">=3.10"
@@ -25,6 +25,9 @@ dependencies = [
25
25
  "myst-parser>=4.0.1",
26
26
  "furo>=2024.8.6",
27
27
  "hatch>=1.14.0",
28
+ "pillow>=11.1.0",
29
+ "numpy>=2.2.4",
30
+ "opencv-python>=4.8.1.78",
28
31
  ]
29
32
  [[project.authors]]
30
33
  name = "Stoupy51"
@@ -1,20 +1,19 @@
1
1
 
2
2
  # Imports
3
3
  from PIL import Image
4
- from typing import Callable
5
- from numpy.typing import NDArray
4
+ from typing import Callable, Any
6
5
  import numpy as np
7
6
 
8
-
9
7
  # Functions
10
8
  def image_resize(
11
- image: Image.Image | NDArray[np.uint8],
9
+ image: Image.Image | np.ndarray[Any, np.dtype[np.uint8]],
12
10
  max_result_size: int,
13
11
  resampling: Image.Resampling = Image.Resampling.LANCZOS,
14
12
  min_or_max: Callable[[int, int], int] = max,
15
- return_type: type[Image.Image | NDArray[np.uint8]] = Image.Image,
16
- ) -> Image.Image | NDArray[np.uint8]:
17
- """ Resize an image while preserving its aspect ratio.
13
+ return_type: type[Image.Image | np.ndarray[Any, np.dtype[np.uint8]]] = Image.Image,
14
+ keep_aspect_ratio: bool = True,
15
+ ) -> Any:
16
+ """ Resize an image while preserving its aspect ratio by default.
18
17
  Scales the image so that its largest dimension equals max_result_size.
19
18
 
20
19
  Args:
@@ -23,8 +22,9 @@ def image_resize(
23
22
  resampling (Image.Resampling): PIL resampling filter to use.
24
23
  min_or_max (Callable): Function to use to get the minimum or maximum of the two ratios.
25
24
  return_type (type): Type of the return value (Image.Image or np.ndarray).
25
+ keep_aspect_ratio (bool): Whether to keep the aspect ratio.
26
26
  Returns:
27
- Image.Image: The resized image with preserved aspect ratio.
27
+ Image.Image | np.ndarray[Any, np.dtype[np.uint8]]: The resized image with preserved aspect ratio.
28
28
  Examples:
29
29
  >>> # Test with (height x width x channels) numpy array
30
30
  >>> import numpy as np
@@ -51,18 +51,33 @@ def image_resize(
51
51
  >>> image_resize(pil_image, 50, resampling=Image.Resampling.NEAREST).size
52
52
  (50, 25)
53
53
  """
54
+ # Convert numpy array to PIL Image if needed
54
55
  if isinstance(image, np.ndarray):
55
- image = Image.fromarray(image) # type: ignore
56
-
57
- width: int = image.size[0]
58
- height: int = image.size[1]
59
- max_dimension: int = min_or_max(width, height)
60
- scale: float = max_result_size / max_dimension
56
+ image = Image.fromarray(image)
61
57
 
62
- new_width: int = int(width * scale)
63
- new_height: int = int(height * scale)
64
- new_image: Image.Image = image.resize((new_width, new_height), resampling)
58
+ if keep_aspect_ratio:
59
+
60
+ # Get original image dimensions
61
+ width: int = image.size[0]
62
+ height: int = image.size[1]
63
+
64
+ # Determine which dimension to use for scaling based on min_or_max function
65
+ max_dimension: int = min_or_max(width, height)
66
+
67
+ # Calculate scaling factor
68
+ scale: float = max_result_size / max_dimension
69
+
70
+ # Calculate new dimensions while preserving aspect ratio
71
+ new_width: int = int(width * scale)
72
+ new_height: int = int(height * scale)
73
+
74
+ # Resize the image with the calculated dimensions
75
+ new_image: Image.Image = image.resize((new_width, new_height), resampling)
76
+ else:
77
+ # If not keeping aspect ratio, resize to square with max_result_size
78
+ new_image: Image.Image = image.resize((max_result_size, max_result_size), resampling)
65
79
 
80
+ # Return the image in the requested format
66
81
  if return_type == np.ndarray:
67
82
  return np.array(new_image)
68
83
  else:
File without changes
File without changes
File without changes