Copy skipped conversions
if input_ext == output_ext:
# If the input and output formats are the same, move the file instead of re-saving it
# self._move_or_error()
print(
f"Skipping conversion for {self.input_path} (already in {self.output_format} format)"
)
return
Add 'jpeg' to supported conversions
SUPPORTED_CONVERSIONS = {
".jpg": {".jpg", ".png", ".bmp", ".webp"},
".png": {".jpg", ".png", ".bmp", ".webp"},
".bmp": {".jpg", ".png", ".bmp", ".webp"},
".webp": {".jpg", ".png", ".bmp", ".webp"},
}
I think then becomes:
SUPPORTED_CONVERSIONS = {
**{ext: {".jpg", ".png", ".bmp", ".webp"}
for ext in [".jpg", ".jpeg"]},
".png": {".jpg", ".png", ".bmp", ".webp"},
".bmp": {".jpg", ".png", ".bmp", ".webp"},
".webp": {".jpg", ".png", ".bmp", ".webp"},
}
but I'm unsure if I'm doing that right.
JPG quality flexibility
First I'd initialize the current hardcoded jpg quality
def __init__(self, input_path: str, output_path: str, output_format: str, jpg_quality=95):
self.jpg_quality = jpg_quality
Then I'd have to pass that in during _convert_to_jpg
rgb_img.save(self.output_path, 'JPEG', quality=self.jpg_quality)