Update my_model/state_manager.py
Browse files- my_model/state_manager.py +15 -12
my_model/state_manager.py
CHANGED
@@ -257,25 +257,28 @@ class StateManager:
|
|
257 |
return st.session_state['images_data']
|
258 |
|
259 |
@staticmethod
|
260 |
-
def resize_image(
|
261 |
"""
|
262 |
-
|
263 |
|
264 |
Args:
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
|
269 |
Returns:
|
270 |
-
|
271 |
"""
|
272 |
-
|
273 |
-
if isinstance(image_path, str):
|
274 |
# Open the image from a file path
|
275 |
-
image = Image.open(
|
276 |
-
elif
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
279 |
return resized_image
|
280 |
|
281 |
|
|
|
257 |
return st.session_state['images_data']
|
258 |
|
259 |
@staticmethod
|
260 |
+
def resize_image(image_input, new_width, new_height):
|
261 |
"""
|
262 |
+
Resize an image given either a file path or a PIL Image object.
|
263 |
|
264 |
Args:
|
265 |
+
image_input (str or Image.Image): The image file path or a PIL Image object.
|
266 |
+
new_width (int): The new width of the image.
|
267 |
+
new_height (int): The new height of the image.
|
268 |
|
269 |
Returns:
|
270 |
+
Image.Image: The resized PIL Image object.
|
271 |
"""
|
272 |
+
if isinstance(image_input, str):
|
|
|
273 |
# Open the image from a file path
|
274 |
+
image = Image.open(image_input)
|
275 |
+
elif isinstance(image_input, Image.Image):
|
276 |
+
# Use the image directly if it's already a PIL Image object
|
277 |
+
image = image_input
|
278 |
+
else:
|
279 |
+
raise ValueError("image_input must be a file path or a PIL Image object")
|
280 |
+
|
281 |
+
resized_image = image.resize((new_width, new_height))
|
282 |
return resized_image
|
283 |
|
284 |
|