mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
add heif/heic support
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -390,7 +390,7 @@ def get_deleteimage(file: str):
|
||||
raise HTTPException(status_code=404, detail=f"file not found: {file}")
|
||||
if os.path.isdir(file):
|
||||
raise HTTPException(status_code=403, detail=f"file {file}: is a directory")
|
||||
if os.path.splitext(file)[1].lower() not in (".png", ".jpg", ".jpeg", ".webp"):
|
||||
if os.path.splitext(file)[1].lower() not in (".png", ".jpg", ".jpeg", ".webp", ".heic", ".heif", ".tiff"):
|
||||
raise HTTPException(status_code=403, detail=f"file {file}: not an image file")
|
||||
try:
|
||||
os.remove(file)
|
||||
@@ -411,7 +411,7 @@ def get_pnginfo(file: str):
|
||||
raise HTTPException(status_code=400, detail="file path is required")
|
||||
if not any(Path(folder).absolute() in Path(file).absolute().parents for folder in allowed_dirs):
|
||||
raise HTTPException(status_code=403, detail=f"file {file}: must be in one of allowed directories")
|
||||
if os.path.splitext(file)[1].lower() not in (".png", ".jpg", ".jpeg", ".webp"):
|
||||
if os.path.splitext(file)[1].lower() not in (".png", ".jpg", ".jpeg", ".webp", ".heic", ".heif", ".tiff"):
|
||||
raise HTTPException(status_code=403, detail=f"file {file}: not an image file")
|
||||
if not os.path.isfile(file):
|
||||
raise HTTPException(status_code=403, detail=f"file {file}: not an image file")
|
||||
|
||||
@@ -112,7 +112,7 @@ def cleanup_tmpdr():
|
||||
for name in files:
|
||||
try:
|
||||
_, extension = os.path.splitext(name)
|
||||
if extension not in {".png", ".jpg", ".webp", ".jxl"}:
|
||||
if extension not in {".png", ".jpg", ".webp", ".jxl", ".heic", ".heif", ".mp4", ".webm"}:
|
||||
continue
|
||||
filename = os.path.join(root, name)
|
||||
os.remove(filename)
|
||||
|
||||
@@ -108,6 +108,11 @@ def atomically_save_image():
|
||||
if shared.opts.image_metadata:
|
||||
debug_save(f'Save exif: {exifinfo}')
|
||||
save_args['exif'] = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: exifinfo_dump } })
|
||||
elif image_format == 'HEIF':
|
||||
save_args = { 'quality': shared.opts.jpeg_quality }
|
||||
if shared.opts.image_metadata:
|
||||
debug_save(f'Save exif: {exifinfo}')
|
||||
save_args['exif'] = piexif.dump({ "Exif": { piexif.ExifIFD.UserComment: exifinfo_dump } })
|
||||
else:
|
||||
save_args = { 'quality': shared.opts.jpeg_quality }
|
||||
try:
|
||||
|
||||
@@ -24,3 +24,14 @@ __all__ = [
|
||||
'draw_text',
|
||||
'flatten',
|
||||
]
|
||||
|
||||
def register_heif():
|
||||
from installer import install
|
||||
install('pillow-heif', quiet=True)
|
||||
try:
|
||||
import pillow_heif
|
||||
pillow_heif.register_heif_opener()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
register_heif()
|
||||
|
||||
@@ -461,7 +461,7 @@ def create_settings(cmd_opts):
|
||||
options_templates.update(options_section(('saving-images', "Image Options"), {
|
||||
"samples_save": OptionInfo(True, "Save all generated images"),
|
||||
"keep_incomplete": OptionInfo(True, "Save interrupted images"),
|
||||
"samples_format": OptionInfo('jpg', 'File format', gr.Dropdown, {"choices": ["jpg", "png", "webp", "tiff", "jp2", "jxl"]}),
|
||||
"samples_format": OptionInfo('jpg', 'File format', gr.Dropdown, {"choices": ["jpg", "png", "webp", "tiff", "jp2", "jxl", "heif"]}),
|
||||
"jpeg_quality": OptionInfo(90, "Image quality", gr.Slider, {"minimum": 1, "maximum": 100, "step": 1}),
|
||||
"img_max_size_mp": OptionInfo(1000, "Maximum image size (MP)", gr.Slider, {"minimum": 10, "maximum": 2000, "step": 1}),
|
||||
"webp_lossless": OptionInfo(False, "WebP lossless compression"),
|
||||
|
||||
@@ -865,7 +865,7 @@ def create_ui(container, button_parent: gr.Button, tabname: str, skip_indexing =
|
||||
if ui.last_item is None:
|
||||
return desc
|
||||
basename = os.path.splitext(ui.last_item.filename)[0]
|
||||
extensions = ['.safetensors', '.ckpt', '.txt', '.json', '.thumb.jpg', '.jpg', '.jpeg', '.png', '.webp', '.tiff', '.jp2', '.jxl']
|
||||
extensions = ['.safetensors', '.ckpt', '.txt', '.json', '.thumb.jpg', '.jpg', '.jpeg', '.png', '.webp', '.tiff', '.jp2', '.jxl', '.heif', '.heic', '.gif']
|
||||
candidates = []
|
||||
for ext in extensions:
|
||||
fn = basename + ext
|
||||
|
||||
Reference in New Issue
Block a user