svg
Browse files- image/remove_metadata.py +19 -1
image/remove_metadata.py
CHANGED
|
@@ -201,6 +201,11 @@ class RemoveMetadata(ImageBase):
|
|
| 201 |
elif format_name in ['BMP', 'GIF']:
|
| 202 |
settings = {} # These formats have limited metadata anyway
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
return settings
|
| 205 |
|
| 206 |
def _clean_png_with_transparency(self, image: Image.Image, output_path: str) -> bool:
|
|
@@ -425,9 +430,15 @@ class RemoveMetadata(ImageBase):
|
|
| 425 |
# Choose appropriate cleaning method based on format
|
| 426 |
success = False
|
| 427 |
|
|
|
|
| 428 |
if original_format == 'PNG' and original_mode in ('RGBA', 'LA', 'P'):
|
| 429 |
success = self._clean_png_with_transparency(image, output_path)
|
| 430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
elif original_format == 'JPEG' or output_path.lower().endswith(('.jpg', '.jpeg')):
|
| 432 |
success = self._clean_jpeg_image(image, output_path)
|
| 433 |
|
|
@@ -449,6 +460,13 @@ class RemoveMetadata(ImageBase):
|
|
| 449 |
|
| 450 |
except Exception as e:
|
| 451 |
logger_config.error(f"Failed to clean image: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
return None, {}
|
| 453 |
|
| 454 |
# Example usage
|
|
|
|
| 201 |
elif format_name in ['BMP', 'GIF']:
|
| 202 |
settings = {} # These formats have limited metadata anyway
|
| 203 |
|
| 204 |
+
elif format_name == 'HEIC':
|
| 205 |
+
settings = {
|
| 206 |
+
'quality': 100 # Maximum quality for HEIC
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
return settings
|
| 210 |
|
| 211 |
def _clean_png_with_transparency(self, image: Image.Image, output_path: str) -> bool:
|
|
|
|
| 430 |
# Choose appropriate cleaning method based on format
|
| 431 |
success = False
|
| 432 |
|
| 433 |
+
# PNG with transparency
|
| 434 |
if original_format == 'PNG' and original_mode in ('RGBA', 'LA', 'P'):
|
| 435 |
success = self._clean_png_with_transparency(image, output_path)
|
| 436 |
+
|
| 437 |
+
# WEBP with transparency (handle like PNG)
|
| 438 |
+
elif original_format == 'WEBP' and original_mode in ('RGBA', 'LA', 'P'):
|
| 439 |
+
success = self._clean_png_with_transparency(image, output_path)
|
| 440 |
+
|
| 441 |
+
# JPEG
|
| 442 |
elif original_format == 'JPEG' or output_path.lower().endswith(('.jpg', '.jpeg')):
|
| 443 |
success = self._clean_jpeg_image(image, output_path)
|
| 444 |
|
|
|
|
| 460 |
|
| 461 |
except Exception as e:
|
| 462 |
logger_config.error(f"Failed to clean image: {str(e)}")
|
| 463 |
+
# Error recovery: clean up partial output
|
| 464 |
+
if 'output_path' in locals() and os.path.exists(output_path):
|
| 465 |
+
try:
|
| 466 |
+
os.unlink(output_path)
|
| 467 |
+
logger_config.info(f"Cleaned up partial output: {output_path}")
|
| 468 |
+
except:
|
| 469 |
+
pass
|
| 470 |
return None, {}
|
| 471 |
|
| 472 |
# Example usage
|