File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ class ConfigSelectionStrategy(AutoEnum):
5454 from botocore .exceptions import ClientError
5555 from PIL import Image
5656
57- def _compress_image_for_bedrock (image_bytes : bytes , max_size_mb : float = 4 .5 ) -> bytes :
57+ def _compress_image_for_bedrock (image_bytes : bytes , max_size_mb : float = 3 .5 ) -> bytes :
5858 """
5959 Compress an image to stay under the specified size limit for Bedrock.
6060
@@ -101,6 +101,7 @@ def _compress_image_for_bedrock(image_bytes: bytes, max_size_mb: float = 4.5) ->
101101
102102 # Check if we're under the size limit
103103 if len (compressed_bytes ) <= max_size_bytes :
104+ print (f'Final compressed image is { len (compressed_bytes ) / (1024 * 1024 ):.2f} MB' )
104105 return compressed_bytes
105106
106107 # If still too large, try reducing quality or scale
@@ -111,9 +112,8 @@ def _compress_image_for_bedrock(image_bytes: bytes, max_size_mb: float = 4.5) ->
111112 quality = 95 # Reset quality when scaling
112113 else :
113114 # If we can't compress enough, return what we have
114- Log .warning (f"Unable to compress image below { max_size_mb } MB limit. "
115- f"Final size: { len (compressed_bytes ) / (1024 * 1024 ):.2f} MB" )
116- return compressed_bytes
115+ raise ValueError (f"Unable to compress image below { max_size_mb } MB limit. "
116+ f"Final size: { len (compressed_bytes ) / (1024 * 1024 ):.2f} MB" )
117117
118118 def process_image_url (image_url : str ) -> Optional [str ]:
119119 """
You can’t perform that action at this time.
0 commit comments