From 49fee7c8dbb7f17e3903c2a238c53ddd53bc503f Mon Sep 17 00:00:00 2001 From: kaanyalova <76952012+kaanyalova@users.noreply.github.com> Date: Sat, 20 Apr 2024 23:18:54 +0300 Subject: [PATCH] Add avif support --- modules/images.py | 13 ++++++++++++- requirements.txt | 1 + requirements_versions.txt | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/images.py b/modules/images.py index c50b2455d..09d3523e8 100644 --- a/modules/images.py +++ b/modules/images.py @@ -13,6 +13,8 @@ import numpy as np import piexif import piexif.helper 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 json import hashlib @@ -569,6 +571,16 @@ def save_image_with_geninfo(image, geninfo, filename, extension=None, existing_p }) 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": image.save(filename, format=image_format, comment=geninfo) 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") if exif_comment: - items['exif comment'] = exif_comment geninfo = exif_comment elif "comment" in items: # for gif geninfo = items["comment"].decode('utf8', errors="ignore") diff --git a/requirements.txt b/requirements.txt index 8699c02be..9e2ecfe4d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -30,3 +30,4 @@ torch torchdiffeq torchsde transformers==4.30.2 +pillow-avif-plugin==1.4.3 \ No newline at end of file diff --git a/requirements_versions.txt b/requirements_versions.txt index 87aae9136..3df74f3d6 100644 --- a/requirements_versions.txt +++ b/requirements_versions.txt @@ -29,3 +29,4 @@ torchdiffeq==0.2.3 torchsde==0.2.6 transformers==4.30.2 httpx==0.24.1 +pillow-avif-plugin==1.4.3