We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3d52d25 commit 532e945Copy full SHA for 532e945
ipyplot/img_helpers.py
@@ -0,0 +1,20 @@
1
+def resize_with_aspect_ratio(img, max_size=1000):
2
+ """Helper function to resize image against the longer edge
3
+
4
+ Args:
5
+ img (PIL.Image):
6
+ Image object to be resized
7
+ max_size (int, optional):
8
+ Max size of the longer edge in pixels.
9
+ Defaults to 2800.
10
11
+ Returns:
12
+ PIL.Image:
13
+ Resized image object
14
+ """
15
+ w, h = img.size
16
+ aspect_ratio = min(max_size/w, max_size/h)
17
+ resized_img = img.resize(
18
+ (int(w * aspect_ratio), int(h * aspect_ratio))
19
+ )
20
+ return resized_img
0 commit comments