Anustup commited on
Commit
5b137a6
·
verified ·
1 Parent(s): 4c2d9c7

Update summarizer.py

Browse files
Files changed (1) hide show
  1. summarizer.py +16 -0
summarizer.py CHANGED
@@ -55,3 +55,19 @@ def create_screenshot_from_scrap_fly(link_to_fetch):
55
  return {"location": location, "success": True}
56
  except Exception as e:
57
  return {"success": False, "error": e}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  return {"location": location, "success": True}
56
  except Exception as e:
57
  return {"success": False, "error": e}
58
+
59
+ def check_and_compress_image(image_path, output_path, target_size_mb=4, max_size_mb=5):
60
+ from PIL import Image
61
+ image_size = os.path.getsize(image_path) / (1024 * 1024) # Convert bytes to MB
62
+ print(f"Original image size: {image_size:.2f} MB")
63
+ if image_size > max_size_mb:
64
+ img = Image.open(image_path)
65
+ quality = 95
66
+ while image_size > target_size_mb and quality > 10:
67
+ img.save(output_path, optimize=True, quality=quality)
68
+ image_size = os.path.getsize(output_path) / (1024 * 1024)
69
+ quality -= 5
70
+ print(f"Compressed image size: {image_size:.2f} MB")
71
+ else:
72
+ print("Image is within size limits, no compression needed.")
73
+