Add avif support
This commit is contained in:
parent
ff6f4680c4
commit
49fee7c8db
|
@ -13,6 +13,8 @@ import numpy as np
|
||||||
import piexif
|
import piexif
|
||||||
import piexif.helper
|
import piexif.helper
|
||||||
from PIL import Image, ImageFont, ImageDraw, ImageColor, PngImagePlugin, ImageOps
|
from PIL import Image, ImageFont, ImageDraw, ImageColor, PngImagePlugin, ImageOps
|
||||||
|
# pillow_avif needs to be imported somewhere in code for it to work
|
||||||
|
import pillow_avif # noqa: F401
|
||||||
import string
|
import string
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -569,6 +571,16 @@ def save_image_with_geninfo(image, geninfo, filename, extension=None, existing_p
|
||||||
})
|
})
|
||||||
|
|
||||||
piexif.insert(exif_bytes, filename)
|
piexif.insert(exif_bytes, filename)
|
||||||
|
elif extension.lower() == '.avif':
|
||||||
|
if opts.enable_pnginfo and geninfo is not None:
|
||||||
|
exif_bytes = piexif.dump({
|
||||||
|
"Exif": {
|
||||||
|
piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(geninfo or "", encoding="unicode")
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
image.save(filename,format=image_format, exif=exif_bytes)
|
||||||
elif extension.lower() == ".gif":
|
elif extension.lower() == ".gif":
|
||||||
image.save(filename, format=image_format, comment=geninfo)
|
image.save(filename, format=image_format, comment=geninfo)
|
||||||
else:
|
else:
|
||||||
|
@ -747,7 +759,6 @@ def read_info_from_image(image: Image.Image) -> tuple[str | None, dict]:
|
||||||
exif_comment = exif_comment.decode('utf8', errors="ignore")
|
exif_comment = exif_comment.decode('utf8', errors="ignore")
|
||||||
|
|
||||||
if exif_comment:
|
if exif_comment:
|
||||||
items['exif comment'] = exif_comment
|
|
||||||
geninfo = exif_comment
|
geninfo = exif_comment
|
||||||
elif "comment" in items: # for gif
|
elif "comment" in items: # for gif
|
||||||
geninfo = items["comment"].decode('utf8', errors="ignore")
|
geninfo = items["comment"].decode('utf8', errors="ignore")
|
||||||
|
|
|
@ -30,3 +30,4 @@ torch
|
||||||
torchdiffeq
|
torchdiffeq
|
||||||
torchsde
|
torchsde
|
||||||
transformers==4.30.2
|
transformers==4.30.2
|
||||||
|
pillow-avif-plugin==1.4.3
|
|
@ -29,3 +29,4 @@ torchdiffeq==0.2.3
|
||||||
torchsde==0.2.6
|
torchsde==0.2.6
|
||||||
transformers==4.30.2
|
transformers==4.30.2
|
||||||
httpx==0.24.1
|
httpx==0.24.1
|
||||||
|
pillow-avif-plugin==1.4.3
|
||||||
|
|
Loading…
Reference in New Issue