rohithk-03 commited on
Commit
d587b98
·
1 Parent(s): 21d9451

update flask app add conversion to RGB from RGBA

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -48,9 +48,15 @@ def fetchImage():
48
 
49
  # Save the image to the current directory
50
  if response.status_code == 200:
51
- with open(file_name, "wb") as file:
52
- file.write(response.content)
53
- print(f"Image downloaded and saved as {file_name}")
 
 
 
 
 
 
54
  else:
55
  print(f"Failed to download image. Status code: {response.status_code}")
56
  # Load image
 
48
 
49
  # Save the image to the current directory
50
  if response.status_code == 200:
51
+ file_name = "downloaded_image.jpg"
52
+
53
+ image = Image.open(io.BytesIO(response.content))
54
+
55
+ if image.mode == "RGBA":
56
+ image = image.convert("RGB")
57
+
58
+ image.save(file_name, "JPEG", quality=100)
59
+ print(f"Image downloaded and saved as {file_name}")
60
  else:
61
  print(f"Failed to download image. Status code: {response.status_code}")
62
  # Load image