-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure package and expand usage options (#46)
- Loading branch information
Showing
3 changed files
with
86 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
"""EXIF stripper.""" | ||
|
||
__version__ = '0.3.1' | ||
from __future__ import annotations | ||
|
||
import os | ||
import platform | ||
|
||
from PIL import Image, UnidentifiedImageError | ||
|
||
__version__ = '0.4.0' | ||
|
||
|
||
def process_image(filename: str | os.PathLike) -> bool: | ||
""" | ||
Process image metadata. | ||
Parameters | ||
---------- | ||
filename : str | os.PathLike | ||
The image file to check. | ||
Returns | ||
------- | ||
bool | ||
Indicator of whether metadata was stripped. | ||
""" | ||
has_changed = False | ||
try: | ||
# remove EXIF data | ||
with Image.open(filename) as im: | ||
if exif := im.getexif(): | ||
exif.clear() | ||
im.save(filename) | ||
has_changed = True | ||
except (FileNotFoundError, UnidentifiedImageError): | ||
pass # not an image | ||
else: | ||
# remove extended attributes (Unix only) | ||
if platform.system() != 'Windows': | ||
from xattr import xattr | ||
|
||
xattr_obj = xattr(filename) | ||
if xattr_obj.list(): | ||
xattr_obj.clear() | ||
has_changed = True | ||
|
||
if has_changed: | ||
print(f'Stripped metadata from {filename}') | ||
|
||
return has_changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters