Skip to content

Commit 49fee7c

Browse files
committed
Add avif support
1 parent ff6f468 commit 49fee7c

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

modules/images.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import piexif
1414
import piexif.helper
1515
from PIL import Image, ImageFont, ImageDraw, ImageColor, PngImagePlugin, ImageOps
16+
# pillow_avif needs to be imported somewhere in code for it to work
17+
import pillow_avif # noqa: F401
1618
import string
1719
import json
1820
import hashlib
@@ -569,6 +571,16 @@ def save_image_with_geninfo(image, geninfo, filename, extension=None, existing_p
569571
})
570572

571573
piexif.insert(exif_bytes, filename)
574+
elif extension.lower() == '.avif':
575+
if opts.enable_pnginfo and geninfo is not None:
576+
exif_bytes = piexif.dump({
577+
"Exif": {
578+
piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(geninfo or "", encoding="unicode")
579+
},
580+
})
581+
582+
583+
image.save(filename,format=image_format, exif=exif_bytes)
572584
elif extension.lower() == ".gif":
573585
image.save(filename, format=image_format, comment=geninfo)
574586
else:
@@ -747,7 +759,6 @@ def read_info_from_image(image: Image.Image) -> tuple[str | None, dict]:
747759
exif_comment = exif_comment.decode('utf8', errors="ignore")
748760

749761
if exif_comment:
750-
items['exif comment'] = exif_comment
751762
geninfo = exif_comment
752763
elif "comment" in items: # for gif
753764
geninfo = items["comment"].decode('utf8', errors="ignore")

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ torch
3030
torchdiffeq
3131
torchsde
3232
transformers==4.30.2
33+
pillow-avif-plugin==1.4.3

requirements_versions.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ torchdiffeq==0.2.3
2929
torchsde==0.2.6
3030
transformers==4.30.2
3131
httpx==0.24.1
32+
pillow-avif-plugin==1.4.3

0 commit comments

Comments
 (0)