-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev(narugo): add support for webp metadata read
- Loading branch information
1 parent
08dbb56
commit 5f39609
Showing
6 changed files
with
129 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .geninfo import read_geninfo_gif, read_geninfo_parameters, read_geninfo_exif | ||
from .lsb import read_lsb_raw_bytes, read_lsb_metadata, write_lsb_raw_bytes, write_lsb_metadata, LSBReadError |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from typing import Optional | ||
|
||
import piexif | ||
from piexif.helper import UserComment | ||
|
||
from ..data import ImageTyping, load_image | ||
|
||
|
||
def read_geninfo_parameters(image: ImageTyping) -> Optional[str]: | ||
image = load_image(image, mode=None, force_background=None) | ||
infos = image.info or {} | ||
return infos.get('parameters') | ||
|
||
|
||
def read_geninfo_exif(image: ImageTyping) -> Optional[str]: | ||
image = load_image(image, mode=None, force_background=None) | ||
infos = image.info or {} | ||
if "exif" in infos: | ||
exif_data = infos["exif"] | ||
try: | ||
exif = piexif.load(exif_data) | ||
except OSError: | ||
# memory / exif was not valid so piexif tried to read from a file | ||
exif = None | ||
|
||
exif_comment = (exif or {}).get("Exif", {}).get(piexif.ExifIFD.UserComment, b"") | ||
try: | ||
exif_comment = UserComment.load(exif_comment) | ||
except ValueError: | ||
exif_comment = exif_comment.decode("utf8", errors="ignore") | ||
|
||
return exif_comment | ||
else: | ||
return None | ||
|
||
|
||
def read_geninfo_gif(image: ImageTyping) -> Optional[str]: | ||
image = load_image(image, mode=None, force_background=None) | ||
infos = image.info or {} | ||
if "comment" in infos: # for gif | ||
return infos["comment"].decode("utf8", errors="ignore") | ||
else: | ||
return None |
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
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
Binary file not shown.