@@ -34,15 +34,22 @@ def __get_image_params(self, image_path):
3434 hosted_image = urllib .parse .urlparse (image_path ).scheme in ("http" , "https" )
3535
3636 if hosted_image :
37- return {"image" : image_path }, {}
37+ image_dims = {"width" : "Undefined" , "height" : "Undefined" }
38+ return {"image" : image_path }, {}, image_dims
3839
3940 image = Image .open (image_path )
41+ dimensions = image .size
42+ image_dims = {"width" : str (dimensions [0 ]), "height" : str (dimensions [1 ])}
4043 buffered = io .BytesIO ()
4144 image .save (buffered , quality = 90 , format = "JPEG" )
4245 data = MultipartEncoder (
4346 fields = {"file" : ("imageToUpload" , buffered .getvalue (), "image/jpeg" )}
4447 )
45- return {}, {"data" : data , "headers" : {"Content-Type" : data .content_type }}
48+ return (
49+ {},
50+ {"data" : data , "headers" : {"Content-Type" : data .content_type }},
51+ image_dims ,
52+ )
4653
4754 def predict (self , image_path , prediction_type = None , ** kwargs ):
4855 """
@@ -54,7 +61,7 @@ def predict(self, image_path, prediction_type=None, **kwargs):
5461 :return: PredictionGroup - a group of predictions based on Roboflow JSON response
5562 :raises Exception: Image path is not valid
5663 """
57- params , request_kwargs = self .__get_image_params (image_path )
64+ params , request_kwargs , image_dims = self .__get_image_params (image_path )
5865
5966 params ["api_key" ] = self .__api_key
6067
@@ -65,5 +72,8 @@ def predict(self, image_path, prediction_type=None, **kwargs):
6572 response .raise_for_status ()
6673
6774 return PredictionGroup .create_prediction_group (
68- response .json (), image_path = image_path , prediction_type = prediction_type
75+ response .json (),
76+ image_path = image_path ,
77+ prediction_type = prediction_type ,
78+ image_dims = image_dims ,
6979 )
0 commit comments