diff --git a/src/formaverter/image_converter.py b/src/formaverter/image_converter.py index d368840..4f7333e 100644 --- a/src/formaverter/image_converter.py +++ b/src/formaverter/image_converter.py @@ -55,7 +55,28 @@ def convert(self) -> None: ) return else: - self._convert_image(input_ext, output_ext) + # Handle JPG conversion separately + if self.output_format.lower() == 'jpg': + self._convert_to_jpg(input_ext, output_ext) + else: + self._convert_image(input_ext, output_ext) + + def _convert_to_jpg(self, input_ext: str, output_ext: str) -> None: + img = Image.open(self.input_path) + + # Ensure the output format is actually JPG + if output_ext.lower() != 'jpg': + output_ext = 'jpg' + + # Save transparency metadata for palette images w/ transparency + if img.mode == 'P' and img.info.get('transparency'): + img = img.convert('RGBA') + + # Convert to RGB + rgb_img = img.convert('RGB') + + # Save as JPG with quality 95 (adjust as needed) + rgb_img.save(self.output_path, 'JPEG', quality=95) def _convert_image(self, input_ext: str, output_ext: str) -> None: """