Skip to content

Commit c760e50

Browse files
authored
Make PNG optimization optional and off by default
1 parent 96df2c9 commit c760e50

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

nodes.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def INPUT_TYPES(cls):
298298
"height": ("INT", {"default": 512, "min": 1, "max": MAX_RESOLUTION, "step": 8}),
299299
"lossless_webp": ("BOOLEAN", {"default": True}),
300300
"quality_jpeg_or_webp": ("INT", {"default": 100, "min": 1, "max": 100}),
301+
"optimize_png": ("BOOLEAN", {"default": False}),
301302
"counter": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff }),
302303
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0}),
303304
"time_format": ("STRING", {"default": "%Y-%m-%d-%H%M%S", "multiline": False}),
@@ -328,6 +329,7 @@ def save_files(
328329
modelname,
329330
quality_jpeg_or_webp,
330331
lossless_webp,
332+
optimize_png,
331333
width,
332334
height,
333335
counter,
@@ -380,12 +382,12 @@ def save_files(
380382
print(f'The path `{output_path.strip()}` specified doesn\'t exist! Creating directory.')
381383
os.makedirs(output_path, exist_ok=True)
382384

383-
filenames = self.save_images(images, output_path, filename, comment, extension, quality_jpeg_or_webp, lossless_webp, prompt, extra_pnginfo)
385+
filenames = self.save_images(images, output_path, filename, comment, extension, quality_jpeg_or_webp, lossless_webp, optimize_png, prompt, extra_pnginfo)
384386

385387
subfolder = os.path.normpath(path)
386388
return {"ui": {"images": map(lambda filename: {"filename": filename, "subfolder": subfolder if subfolder != '.' else '', "type": 'output'}, filenames)}}
387389

388-
def save_images(self, images, output_path, filename_prefix, comment, extension, quality_jpeg_or_webp, lossless_webp, prompt=None, extra_pnginfo=None) -> list[str]:
390+
def save_images(self, images, output_path, filename_prefix, comment, extension, quality_jpeg_or_webp, lossless_webp, optimize_png, prompt=None, extra_pnginfo=None) -> list[str]:
389391
img_count = 1
390392
paths = list()
391393
for image in images:
@@ -405,7 +407,7 @@ def save_images(self, images, output_path, filename_prefix, comment, extension,
405407
metadata.add_text(x, json.dumps(extra_pnginfo[x]))
406408

407409
filename = f"{filename_prefix}.png"
408-
img.save(os.path.join(output_path, filename), pnginfo=metadata, optimize=True)
410+
img.save(os.path.join(output_path, filename), pnginfo=metadata, optimize=optimize_png)
409411
else:
410412
filename = f"{filename_prefix}.{extension}"
411413
file = os.path.join(output_path, filename)

0 commit comments

Comments
 (0)