Added support for .jfif previews.
This commit is contained in:
11
__init__.py
11
__init__.py
@@ -34,11 +34,13 @@ ui_settings_uri = os.path.join(extension_uri, "ui_settings.yaml")
|
|||||||
server_settings_uri = os.path.join(extension_uri, "server_settings.yaml")
|
server_settings_uri = os.path.join(extension_uri, "server_settings.yaml")
|
||||||
|
|
||||||
fallback_model_extensions = set([".bin", ".ckpt", ".onnx", ".pt", ".pth", ".safetensors"]) # TODO: magic values
|
fallback_model_extensions = set([".bin", ".ckpt", ".onnx", ".pt", ".pth", ".safetensors"]) # TODO: magic values
|
||||||
|
jpeg_format_names = ["JPG", "JPEG", "JFIF"]
|
||||||
image_extensions = (
|
image_extensions = (
|
||||||
".png", # order matters
|
".png", # order matters
|
||||||
".webp",
|
".webp",
|
||||||
".jpeg",
|
".jpeg",
|
||||||
".jpg",
|
".jpg",
|
||||||
|
".jfif",
|
||||||
".gif",
|
".gif",
|
||||||
".apng",
|
".apng",
|
||||||
)
|
)
|
||||||
@@ -47,6 +49,7 @@ stable_diffusion_webui_civitai_helper_image_extensions = (
|
|||||||
".preview.webp",
|
".preview.webp",
|
||||||
".preview.jpeg",
|
".preview.jpeg",
|
||||||
".preview.jpg",
|
".preview.jpg",
|
||||||
|
".preview.jfif",
|
||||||
".preview.gif",
|
".preview.gif",
|
||||||
".preview.apng",
|
".preview.apng",
|
||||||
)
|
)
|
||||||
@@ -312,11 +315,11 @@ def image_format_is_equal(f1, f2):
|
|||||||
if f2[0] == ".": f2 = f2[1:]
|
if f2[0] == ".": f2 = f2[1:]
|
||||||
f1 = f1.upper()
|
f1 = f1.upper()
|
||||||
f2 = f2.upper()
|
f2 = f2.upper()
|
||||||
return f1 == f2 or (f1 == "JPG" and f2 == "JPEG") or (f1 == "JPEG" and f2 == "JPG")
|
return f1 == f2 or (f1 in jpeg_format_names and f2 in jpeg_format_names)
|
||||||
|
|
||||||
|
|
||||||
def get_auto_thumbnail_format(original_format):
|
def get_auto_thumbnail_format(original_format):
|
||||||
if original_format in ["JPEG", "WEBP", "JPG"]:
|
if original_format in ["JPEG", "WEBP", "JPG"]: # JFIF?
|
||||||
return original_format
|
return original_format
|
||||||
return "JPEG" # default fallback
|
return "JPEG" # default fallback
|
||||||
|
|
||||||
@@ -376,7 +379,7 @@ async def get_model_preview(request):
|
|||||||
if not image_format_is_equal(response_image_format, image_format):
|
if not image_format_is_equal(response_image_format, image_format):
|
||||||
exif = image.getexif()
|
exif = image.getexif()
|
||||||
metadata = get_image_info(image)
|
metadata = get_image_info(image)
|
||||||
if response_image_format in ['JPEG', 'JPG']:
|
if response_image_format in jpeg_format_names:
|
||||||
image = image.convert('RGB')
|
image = image.convert('RGB')
|
||||||
image_bytes = io.BytesIO()
|
image_bytes = io.BytesIO()
|
||||||
image.save(image_bytes, format=response_image_format, exif=exif, pnginfo=metadata, quality=quality)
|
image.save(image_bytes, format=response_image_format, exif=exif, pnginfo=metadata, quality=quality)
|
||||||
@@ -424,7 +427,7 @@ async def get_model_preview(request):
|
|||||||
resampling_method = Image.Resampling.BICUBIC
|
resampling_method = Image.Resampling.BICUBIC
|
||||||
image.thumbnail((w, h), resample=resampling_method)
|
image.thumbnail((w, h), resample=resampling_method)
|
||||||
|
|
||||||
if not image_format_is_equal(image_format, response_image_format) and response_image_format in ['JPEG', 'JPG']:
|
if not image_format_is_equal(image_format, response_image_format) and response_image_format in jpeg_format_names:
|
||||||
image = image.convert('RGB')
|
image = image.convert('RGB')
|
||||||
image_bytes = io.BytesIO()
|
image_bytes = io.BytesIO()
|
||||||
image.save(image_bytes, format=response_image_format, exif=exif, pnginfo=metadata, quality=quality)
|
image.save(image_bytes, format=response_image_format, exif=exif, pnginfo=metadata, quality=quality)
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ const IMAGE_EXTENSIONS = [
|
|||||||
".webp",
|
".webp",
|
||||||
".jpeg",
|
".jpeg",
|
||||||
".jpg",
|
".jpg",
|
||||||
|
".jfif",
|
||||||
".gif",
|
".gif",
|
||||||
".apng",
|
".apng",
|
||||||
|
|
||||||
@@ -170,6 +171,7 @@ const IMAGE_EXTENSIONS = [
|
|||||||
".preview.webp",
|
".preview.webp",
|
||||||
".preview.jpeg",
|
".preview.jpeg",
|
||||||
".preview.jpg",
|
".preview.jpg",
|
||||||
|
".preview.jfif",
|
||||||
".preview.gif",
|
".preview.gif",
|
||||||
".preview.apng",
|
".preview.apng",
|
||||||
]; // TODO: /model-manager/image/extensions
|
]; // TODO: /model-manager/image/extensions
|
||||||
|
|||||||
Reference in New Issue
Block a user