Skip to content

Commit ee01a62

Browse files
authored
Fix JPG export (#301)
It was in the definition of supported file formats, but the export was hardcoded to PNG.
1 parent 84a3728 commit ee01a62

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

gradia/graphics/image.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from gradia.graphics.background import Background
3131
from gradia.ui.widget.preset_button import ImagePresetButton
3232
from gradia.app_constants import PRESET_IMAGES
33+
from gradia.app_constants import SUPPORTED_EXPORT_FORMATS
3334

3435
class ImageBackground(Background):
3536
@property
@@ -69,7 +70,13 @@ def load_image(self, path: str) -> None:
6970
def save_image_copy_async(self) -> None:
7071
def save_in_background():
7172
if self.image:
72-
self.image.save(self.SAVED_IMAGE_PATH, 'PNG')
73+
_, extension = os.path.splitext(self.SAVED_IMAGE_PATH)
74+
target_format = 'PNG'
75+
for format in SUPPORTED_EXPORT_FORMATS:
76+
if extension.lower() in format['extensions']:
77+
target_format = format['shortname']
78+
break
79+
self.image.save(self.SAVED_IMAGE_PATH, target_format)
7380

7481
thread = threading.Thread(target=save_in_background, daemon=True)
7582
thread.start()

0 commit comments

Comments
 (0)