m7mdal7aj commited on
Commit
5313b6c
1 Parent(s): cf8c147

Update my_model/state_manager.py

Browse files
Files changed (1) hide show
  1. 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(image_path, new_width, new_height):
261
  """
262
- Resizes an image from the specified to the given dimensions.
263
 
264
  Args:
265
- image_path (str): Path to the image file.
266
- new_width (int): Desired width for the resized image.
267
- new_height (int): Desired height for the resized image.
268
 
269
  Returns:
270
- Image: The resized image object.
271
  """
272
-
273
- if isinstance(image_path, str):
274
  # Open the image from a file path
275
- image = Image.open(image_path)
276
- elif hasattr(image_path, 'read'):
277
- resized_image = image.resize((new_width, new_height))
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