Alibrown commited on
Commit
b15e399
·
verified ·
1 Parent(s): c782af6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -6,8 +6,11 @@ import time
6
 
7
  def compress_image(image, format='webp', quality=85):
8
  try:
 
 
 
9
  img_byte_arr = io.BytesIO()
10
- image.save(img_byte_arr, format=format.upper(), quality=quality)
11
  img_byte_arr.seek(0)
12
  return Image.open(img_byte_arr)
13
  except Exception as e:
@@ -28,6 +31,7 @@ def main():
28
 
29
  # Aktuelles Format ermitteln
30
  current_format = original_image.format.lower() if original_image.format else uploaded_file.name.split('.')[-1].lower()
 
31
 
32
  st.subheader("Originalbild")
33
  st.image(original_image, caption=f"Ursprüngliches Bild ({current_format.upper()})")
@@ -69,8 +73,11 @@ def main():
69
  time.sleep(0.5)
70
 
71
  if optimized_image:
 
 
 
72
  img_byte_arr = io.BytesIO()
73
- optimized_image.save(img_byte_arr, format=target_format.upper(), quality=compression_quality)
74
  img_byte_arr.seek(0)
75
 
76
  progress_bar.progress(100)
 
6
 
7
  def compress_image(image, format='webp', quality=85):
8
  try:
9
+ # Korrektur: Wandle 'jpg' in 'jpeg' um
10
+ save_format = 'jpeg' if format.lower() == 'jpg' else format
11
+
12
  img_byte_arr = io.BytesIO()
13
+ image.save(img_byte_arr, format=save_format.upper(), quality=quality)
14
  img_byte_arr.seek(0)
15
  return Image.open(img_byte_arr)
16
  except Exception as e:
 
31
 
32
  # Aktuelles Format ermitteln
33
  current_format = original_image.format.lower() if original_image.format else uploaded_file.name.split('.')[-1].lower()
34
+ current_format = 'jpeg' if current_format == 'jpg' else current_format
35
 
36
  st.subheader("Originalbild")
37
  st.image(original_image, caption=f"Ursprüngliches Bild ({current_format.upper()})")
 
73
  time.sleep(0.5)
74
 
75
  if optimized_image:
76
+ # Korrektur: Speichern mit korrektem Format
77
+ save_format = 'jpeg' if target_format.lower() == 'jpg' else target_format
78
+
79
  img_byte_arr = io.BytesIO()
80
+ optimized_image.save(img_byte_arr, format=save_format.upper(), quality=compression_quality)
81
  img_byte_arr.seek(0)
82
 
83
  progress_bar.progress(100)