Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d53328c8ac | ||
|
|
85967a9a4b | ||
|
|
bfabb38bea | ||
|
|
2a2e38397a | ||
|
|
54e9183ecd | ||
|
|
669e7a9d03 | ||
|
|
ab2410ba95 | ||
|
|
6369fb315f | ||
|
|
fc67d2b6b0 |
@@ -1,5 +1,7 @@
|
||||
# 💾 Save Image Extended for ComfyUI
|
||||
**AVIF** / **WebP** / **JXL** support!
|
||||
Save as AVIF, WebP, JPEG, customize the folder, sub-folders, and filenames of your images!
|
||||
|
||||
Supports those extensions: **AVIF WebP JXL jpg jpeg png gif tiff bmp**
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/save-image-extended-comfyui-example.png" />
|
||||
@@ -8,18 +10,60 @@
|
||||
* Customize the folder, sub-folders, and filenames of your images!
|
||||
* Save data about the generated job (sampler, prompts, models) as entries in a `json` (text) file, in each folder.
|
||||
* Use the values of ANY node's widget, by simply adding its badge number in the form _id.widget_name_
|
||||
* Oh btw... also saves your output as **AVIF** / **WebP** / **JPEG** / **JXL** ... And yes the prompt is included :)
|
||||
* ComfyUI can only load PNG and WebP atm
|
||||
* Promt saved in jpeg and AVIF, but ComfyUI can only load PNG and WebP atm
|
||||
|
||||
|
||||
<br>
|
||||
<p align="center">
|
||||
<img src="assets/save-image-extended-comfyui-named_nodes_widgets-example.png" />
|
||||
<br><br>
|
||||
Happy saving!
|
||||
</p>
|
||||
|
||||
*Reboot by AudioscavengeR since 2024-05-05, original idea from [@thedyze](https://github.com/thedyze/save-image-extended-comfyui)*
|
||||
## Parameters / Usage
|
||||
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| `filename_prefix` | String prefix added to files. |
|
||||
| `filename_keys` | Comma separated string with sampler parameters to add to filename. E.g: `sampler_name, scheduler, cfg, denoise` Added to filename in written order. `resolution` also works. `vae_name` `model_name` (upscale model), `ckpt_name` (checkpoint) are others that should work. Here you can try any parameter name of any node. As long as the parameter has the same variable name defined in the `prompt` object they should work. The same applies to `foldername_keys`. |
|
||||
| `foldername_prefix` | String prefix added to folders. |
|
||||
| `foldername_keys` | Comma separated string with _sampler_ parameters to add to foldername. Add more subfolders by prepending "./" to the key name. |
|
||||
| `delimiter` | **now a free field** Delimiter = 1 character, can be anything your file system supports. Windows users should still use "/" for subfolders. |
|
||||
| `save_job_data` | If enabled, saves information about each job as entries in a `jobs.json` text file, inside the generated folder. Mulitple options for saving `prompt`, `basic data`, `sampler settings`, `loaded models`. |
|
||||
| `job_data_per_image` | When enabled, saves individual job data files for each image. |
|
||||
| `job_custom_text` | Custom string to save along with the job data. Right click the node and convert to input to connect with another node. |
|
||||
| `save_metadata` | Saves metadata into the image. |
|
||||
| `counter_digits` | Number of digits used for the image counter. `3` = image_001.png. Will adjust the counter if files are deleted. Looks for the highest number in the folder, does not fill gaps. |
|
||||
| `counter_position` | Image counter first or last in the filename. |
|
||||
| `one_counter_per_folder` | Toggles the counter. Either one counter per folder, or resets when a parameter/prompt changes. |
|
||||
| `image_preview` | Turns the image preview on and off. |
|
||||
| `output_ext` | File extension: PNG by default, or WEBP (coming soon). |
|
||||
|
||||
Unknown key names in `filename_keys` and `foldername_keys` are treated as custom strings: if you enter `wrongNumber.attribute`, you will get `attribute` in your filename.
|
||||
|
||||
Datetime UNIX format is now included! `%Y-%m-%d` or `%F` etc
|
||||
|
||||
## Node inputs
|
||||
|
||||
- `images` - The generated images.
|
||||
|
||||
Optional:
|
||||
- `positive_text_opt` - Optional string input for when using custom nodes for positive prompt text.
|
||||
- `negative_text_opt` - Optional string input for when using custom nodes for negative prompt text.
|
||||
|
||||
## Automatic date/time conversion in file/folder names
|
||||
|
||||
Converts [unix datetime formats](https://www.man7.org/linux/man-pages/man1/date.1.html):
|
||||
|
||||
| Unix datetime | Example | Comment |
|
||||
| --- | --- | --- |
|
||||
| %F or %Y-%m-%d | 2024-05-22 | |
|
||||
| %D | 05/22/24 | This effectively creates subfolders |
|
||||
| %F %H-%M-%S | 2024-05-22 09-13-58 | |
|
||||
| %Y/%V | 2024/21 | year subfolder / ISO week number subfolder |
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/save-image-extended-comfyui-example-2.png" />
|
||||
</p>
|
||||
|
||||
## Installation
|
||||
### Requirements:
|
||||
@@ -47,63 +91,36 @@ pip install jxlpy
|
||||
git clone https://github.com/audioscavenger/save-image-extended-comfyui
|
||||
```
|
||||
|
||||
## Parameters / Usage
|
||||
| Attribute | Description |
|
||||
| --- | --- |
|
||||
| `filename_prefix` | String prefix added to files. |
|
||||
| `filename_keys` | Comma separated string with sampler parameters to add to filename. E.g: `sampler_name, scheduler, cfg, denoise` Added to filename in written order. `resolution` also works. `vae_name` `model_name` (upscale model), `ckpt_name` (checkpoint) are others that should work. Here you can try any parameter name of any node. As long as the parameter has the same variable name defined in the `prompt` object they should work. The same applies to `foldername_keys`. |
|
||||
| `foldername_prefix` | String prefix added to folders. |
|
||||
| `foldername_keys` | Comma separated string with _sampler_ parameters to add to foldername. Add more subfolders by prepending "./" to the key name. |
|
||||
| `delimiter` | **now a free field** Delimiter = 1 character, can be anything your file system supports. Windows users should still use "/" for subfolders. |
|
||||
| `save_job_data` | If enabled, saves information about each job as entries in a `jobs.json` text file, inside the generated folder. Mulitple options for saving `prompt`, `basic data`, `sampler settings`, `loaded models`. |
|
||||
| `job_data_per_image` | When enabled, saves individual job data files for each image. |
|
||||
| `job_custom_text` | Custom string to save along with the job data. Right click the node and convert to input to connect with another node. |
|
||||
| `save_metadata` | Saves metadata into the image. |
|
||||
| `counter_digits` | Number of digits used for the image counter. `3` = image_001.png. Will adjust the counter if files are deleted. Looks for the highest number in the folder, does not fill gaps. |
|
||||
| `counter_position` | Image counter first or last in the filename. |
|
||||
| `one_counter_per_folder` | Toggles the counter. Either one counter per folder, or resets when a parameter/prompt changes. |
|
||||
| `image_preview` | Turns the image preview on and off. |
|
||||
| `output_ext` | File extension: PNG by default, or WEBP (coming soon). |
|
||||
|
||||
Unknown key names in `filename_keys` and `foldername_keys` are treated as custom strings: if you enter `wrongNumber.attribute`, you will get `attribute` in your filename.
|
||||
|
||||
## Node inputs
|
||||
|
||||
- `images` - The generated images.
|
||||
|
||||
Optional:
|
||||
- `positive_text_opt` - Optional string input for when using custom nodes for positive prompt text.
|
||||
- `negative_text_opt` - Optional string input for when using custom nodes for negative prompt text.
|
||||
|
||||
## Automatic folder names and date/time in names
|
||||
|
||||
Convert the 'prefix' parameters to inputs (right click in the node and select e.g 'convert foldername_prefix to input'. Then attach the 'Get Date Time String' custom node from JPS to these inputs. This way a new folder name can be automatically generated each time generate is pressed.
|
||||
## Miscelaneous
|
||||
#
|
||||
Disclaimer: Does not check for illegal characters entered in file or folder names. May not be compatible with every other custom node, depending on changes in the `prompt` object.
|
||||
Tested and working with default samplers, Efficiency nodes, UltimateSDUpscale, ComfyRoll, composer, NegiTools, and 45 other nodes.
|
||||
|
||||
#
|
||||
Quality and compression settings:
|
||||
Quality and compression settings: default is 75, 100 will activate **lossless** for AVIF and WEBP only.
|
||||
|
||||
* AVIF quality is fixed at 60.
|
||||
* WebP quality is fixed at 75.
|
||||
* JPEG quality is fixed at 91.
|
||||
* JXL quality is fixed at 91.
|
||||
* PNG is maxed compressed (9)
|
||||
|
||||
Start a discussion or a poll if you want to change output quality, and add another attribute in the node. There's so many already, some complain about the node being too tall.
|
||||
Quick comparison of size per extension, for the same picture, AVIF quality=60, WebP quality=75, jpeg quality=91 (and yes, AVIF still looks better then WebP):
|
||||
|
||||
<p align="center">
|
||||
<img src="assets/save-image-extended-sizes-comparison.png" />
|
||||
</p>
|
||||
|
||||
#
|
||||
About extensions WebP AVIF JPEG JXL: ComfyUI can only load PNG and WebP atm... Feel free to ask ComfyUI team to add support for AVIF/jpeg/JXL!
|
||||
|
||||
The prompt is included under the **EXIF** tag `UserComment` (IFD0 / 0x9286) as defined [here](https://exiftool.org/TagNames/EXIF.html).
|
||||
It is saved in this form: `UserComment = {"prompt": {"1": {"inputs": {...}}}}`.
|
||||
The metadata Are included under the **EXIF** tags IFD0 as defined [here](https://exiftool.org/TagNames/EXIF.html)
|
||||
|
||||
| Data | EXIF | Name | String looks like |
|
||||
| --- | --- | --- | --- |
|
||||
| prompt | 0x9286 | UserComment | Prompt: {"5" ... } |
|
||||
| workflow | 0x010e | ImageDescription | Workflow: {"5" ... } |
|
||||
|
||||
You can retrieve the prompt manually with [exiftool](https://exiftool.org/), here are some example commands:
|
||||
- `exiftool -Parameters -Prompt -Workflow file.png`
|
||||
- `exiftool -Parameters -UserComment -Prompt -Workflow file.{jpg|webp|avif}`
|
||||
- `exiftool -Parameters -Prompt -Workflow image.png`
|
||||
- `exiftool -Parameters -UserComment -ImageDescription image.{jpg|jpeg|webp|avif|jxl}`
|
||||
|
||||
#
|
||||
ComfyUI cannot load lossless WebP atm. Feel free to try and fix `pnginfo.js`
|
||||
|
||||
#
|
||||
Incompatible with *extended-saveimage-comfyui* - This node can be safely discarded, as it only offers WebP output. My node already adds JPEG and WebP.
|
||||
@@ -127,6 +144,7 @@ jobs.json sample: always generated and appended, not sure what it can be used fo
|
||||
|
||||
|
||||
## RoadMap
|
||||
*Reboot by AudioscavengeR since 2024-05-05, original idea from [@thedyze](https://github.com/thedyze/save-image-extended-comfyui)*
|
||||
|
||||
I won't promise you the moon, but since I use this node myself, I will maintain it as much as I can. I do provide a way to contact me, and will accept PR and collabs.
|
||||
Once I feel like I don't have time to work on it, I will gladly transfer ownership or let collabs maintain it.
|
||||
@@ -142,8 +160,24 @@ TODO:
|
||||
- [ ] offer to place the counter anywhere, as a key in filename_keys
|
||||
- [ ] files can get out of order if prefixes change... that is expected, but is this what we want? another reason to have the counter place anywhere we want
|
||||
|
||||
### release 2.62 💾
|
||||
- prompt and workflow are saved in IFD 270 and 271 for better load compatibility
|
||||
- disabled jobs.json by default, this thingy seems useless to me
|
||||
|
||||
### release 2.61 💾
|
||||
- added quality input
|
||||
|
||||
### release 2.60 💾
|
||||
- added extensions jpeg, gif, tiff, bmp
|
||||
- added image_optimization (only for jpeg)
|
||||
- now saves prompt and workflow separately into 0x9286/UserComment and 0x010e/ImageDescription
|
||||
|
||||
### release 2.51 💾
|
||||
- added unix datetime formats
|
||||
|
||||
### release 2.50 💾
|
||||
- added JXL support
|
||||
- added 'BOOLEAN' support
|
||||
|
||||
### release 2.46 💾
|
||||
- bug discovered with *rgthree's Ksampler Config*: using `steps_total` as an input to a Ksampler, will issue the index of the output, instead of the steps value ("\[nodeNum, 0]" instead of steps value). FIX: use `steps_total` instead of `steps`!
|
||||
@@ -193,3 +227,5 @@ TODO:
|
||||
### release 2.0
|
||||
- [x] Reboot on 2024-05-05
|
||||
|
||||
## :ribbon: Licence
|
||||
[GPL 3.0](https://choosealicense.com/licenses/gpl-3.0/)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
+84
-43
@@ -44,22 +44,25 @@ original_locale = locale.setlocale(locale.LC_TIME, '')
|
||||
|
||||
# class SaveImageExtended -------------------------------------------------------------------------------
|
||||
class SaveImageExtended:
|
||||
version = 2.50
|
||||
version = 2.62
|
||||
type = 'output'
|
||||
|
||||
png_compress_level = 9
|
||||
lossless = False
|
||||
avif_quality = 60
|
||||
webp_quality = 75
|
||||
jpeg_quality = 91
|
||||
jxl_quality = 91
|
||||
# tiff_quality has no impact unless you start meddling with the compressions algorithms
|
||||
tiff_quality = 91
|
||||
# optimize_image only works for jpeg, with like just 2% reduction in size
|
||||
optimize_image = True
|
||||
|
||||
filename_prefix = 'ComfyUI'
|
||||
filename_keys = 'sampler_name, scheduler, cfg, steps'
|
||||
filename_keys = 'sampler_name, cfg, steps, %F %H-%M-%S'
|
||||
foldername_prefix = ''
|
||||
foldername_keys = 'ckpt_name, ./subfolder'
|
||||
delimiter = '_'
|
||||
save_job_data = 'basic, models, sampler, prompt'
|
||||
foldername_keys = 'ckpt_name'
|
||||
delimiter = '-'
|
||||
save_job_data = 'disabled'
|
||||
job_data_per_image = False
|
||||
job_custom_text = ''
|
||||
save_metadata = True
|
||||
@@ -70,7 +73,8 @@ class SaveImageExtended:
|
||||
image_preview = True
|
||||
extToRemove = ['.safetensors', '.ckpt', '.pt', '.bin', '.pth']
|
||||
output_ext = '.webp'
|
||||
output_exts = ['.webp', '.png', '.jpg']
|
||||
output_exts = ['.webp', '.png', '.jpg', '.jpeg', '.gif', '.tiff', '.bmp']
|
||||
quality = 75
|
||||
|
||||
print(f"\033[92m[save_image_extended]\033[0m version: {version}\033[0m")
|
||||
if jxl_supported:
|
||||
@@ -115,9 +119,9 @@ class SaveImageExtended:
|
||||
'basic, sampler, prompt',
|
||||
'basic, models, sampler, prompt'
|
||||
], {'default': self.save_job_data}),
|
||||
'job_data_per_image': ([False, True], {'default': self.job_data_per_image}),
|
||||
'job_data_per_image': ('BOOLEAN', {"default": self.job_data_per_image}),
|
||||
'job_custom_text': ('STRING', {'default': self.job_custom_text, 'multiline': False}),
|
||||
'save_metadata': ([True, False], {'default': self.save_metadata}),
|
||||
'save_metadata': ('BOOLEAN', {'default': self.save_metadata}),
|
||||
'counter_digits': ('INT', {
|
||||
"default": self.counter_digits,
|
||||
"min": 1,
|
||||
@@ -126,9 +130,16 @@ class SaveImageExtended:
|
||||
"display": "silder"
|
||||
}),
|
||||
'counter_position': (self.counter_positions, {'default': self.counter_position}),
|
||||
'one_counter_per_folder': ([True, False], {'default': self.one_counter_per_folder}),
|
||||
'image_preview': ([True, False], {'default': self.image_preview}),
|
||||
'one_counter_per_folder': ('BOOLEAN', {'default': self.one_counter_per_folder}),
|
||||
'image_preview': ('BOOLEAN', {'default': self.image_preview}),
|
||||
'output_ext': (self.output_exts, {'default': self.output_ext}),
|
||||
'quality': ('INT', {
|
||||
"default": self.quality,
|
||||
"min": 1,
|
||||
"max": 100,
|
||||
"step": 1,
|
||||
"display": "silder"
|
||||
}),
|
||||
},
|
||||
'optional': {
|
||||
'positive_text_opt': ('STRING', {'forceInput': True}),
|
||||
@@ -232,8 +243,12 @@ class SaveImageExtended:
|
||||
# Fractions and Superscripts '⅔','2²' False True True
|
||||
# Roman Numerals 'ↁ' False False True
|
||||
# --------------------------- --------- ----------- --------- -----------
|
||||
def generate_custom_name(self, keys_to_extract, prefix, delimiter, prompt):
|
||||
def generate_custom_name(self, keys_to_extract, prefix, delimiter, prompt, timestamp=datetime.now()):
|
||||
if '%' in prefix:
|
||||
custom_name = timestamp.strftime(prefix)
|
||||
else:
|
||||
custom_name = prefix
|
||||
|
||||
if prompt is not None and keys_to_extract != ['']:
|
||||
found_values = {}
|
||||
# print(f"debug generate_custom_name: --prefix: {prefix}")
|
||||
@@ -248,17 +263,21 @@ class SaveImageExtended:
|
||||
# 'inputs': {'cfg': 1.6,
|
||||
# 'denoise': 1.0, ...
|
||||
for key in keys_to_extract:
|
||||
if not key: continue
|
||||
|
||||
value = None
|
||||
node, nodeKey = None, None
|
||||
|
||||
# check if this is a subfolder: starts with ./ or /, can also end with /
|
||||
if '/' in key:
|
||||
# we also exclude datetime formats like "%A %d. %B %Y"
|
||||
if '/' in key and not '%' in key:
|
||||
# key is a subfolder: ./subfolder or ../subfolder or /subfolder
|
||||
value = key
|
||||
else:
|
||||
splitKey = key.split('.')
|
||||
# we also exclude cases like "..string" or "sting.string.x" etc
|
||||
if len(splitKey) == 2:
|
||||
# we also exclude datetime formats like "%A %d. %B %Y"
|
||||
if len(splitKey) == 2 and not '%' in key:
|
||||
# key has the form string.string
|
||||
if '' not in splitKey:
|
||||
# key has the form string.string
|
||||
@@ -280,7 +299,11 @@ class SaveImageExtended:
|
||||
# key is in the form ".string" or "string." or "." - we won't clean that up and keep as is, maybe it's a separator
|
||||
value = key
|
||||
else:
|
||||
# nodeKey is not a folder, has no dot, or multiple dots, could be a valid key to find, could be a fixed string - keep as is
|
||||
# could be a datetime format
|
||||
if '%' in key:
|
||||
value = timestamp.strftime(key)
|
||||
# nodeKey is not a datetime, folder, has no dot, or multiple dots, could be a valid key to find, could be a fixed string - keep as is
|
||||
else:
|
||||
nodeKey = key
|
||||
self.find_keys_recursively(prompt, [nodeKey], found_values)
|
||||
# is key num.widget_name
|
||||
@@ -326,7 +349,7 @@ class SaveImageExtended:
|
||||
return custom_name.strip(delimiter).strip('.').strip('/').strip(delimiter)
|
||||
|
||||
|
||||
def save_job_to_json(self, save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, filename):
|
||||
def save_job_to_json(self, save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, filename, timestamp=datetime.now()):
|
||||
prompt_keys_to_save = {}
|
||||
if 'basic' in save_job_data:
|
||||
if len(filename_prefix) > 0:
|
||||
@@ -411,7 +434,7 @@ class SaveImageExtended:
|
||||
print(f"SaveImageExtended {version} error: The file {json_file_path} is empty or malformed. Initializing with empty data.")
|
||||
existing_data = {}
|
||||
|
||||
timestamp = datetime.now().strftime('%c')
|
||||
timestamp = timestamp.strftime('%c')
|
||||
new_entry = {}
|
||||
new_entry[timestamp] = prompt_keys_to_save
|
||||
existing_data.update(new_entry)
|
||||
@@ -441,7 +464,8 @@ class SaveImageExtended:
|
||||
## For Comfy to load an image, it need a PNG tag at the root: Prompt={prompt}
|
||||
## For AVIF WebP Jpeg, it's only Exif that's available... and UserComment is the best choice.
|
||||
|
||||
## This method gives wrong results, as [ExifTool] will issue Warning: Invalid EXIF text encoding for UserComment
|
||||
## This method gives good results, as long as you save the prompt/workflow in 2 separate Exif tags
|
||||
## Otherwise, [ExifTool] will issue Warning: Invalid EXIF text encoding for UserComment
|
||||
# entryOffset 10
|
||||
# tag 37510
|
||||
# type 2
|
||||
@@ -452,9 +476,17 @@ class SaveImageExtended:
|
||||
exif = img.getexif()
|
||||
dump = json.dumps(metadata)
|
||||
# print(f"dump={dump}") {"prompt": { .. }, "workflow": { .. }}
|
||||
exif[ExifTags.Base.UserComment] = json.dumps(metadata)
|
||||
# This should work the same:
|
||||
# exif[0x9286] = json.dumps(metadata)
|
||||
# exif[ExifTags.Base.UserComment] = dump
|
||||
|
||||
## It seems better to separate the two
|
||||
# 0x010e: ImageDescription
|
||||
# 0x010f: Make
|
||||
# 0x9286: UserComment
|
||||
# both prompt and workflow must be in IFD close together of that can cause problems for the parseIFD function on import
|
||||
# https://exiftool.org/TagNames/EXIF.html
|
||||
# exif[0x9286] = "Prompt: " + json.dumps(metadata['prompt']) # UserComment
|
||||
exif[0x010f] = "Prompt: " + json.dumps(metadata['prompt']) # Make
|
||||
exif[0x010e] = "Workflow: " + json.dumps(metadata['workflow']) # ImageDescription
|
||||
|
||||
# exif[ExifTags.Base.UserComment] = piexif.helper.UserComment.dump(json.dumps(metadata), encoding="unicode") # type 4
|
||||
# exif[ExifTags.Base.UserComment] = piexif.helper.UserComment.dump(json.dumps(metadata), encoding="jis") # type 1
|
||||
@@ -490,35 +522,42 @@ class SaveImageExtended:
|
||||
return exif_dat
|
||||
|
||||
|
||||
def save_image(self, image_path, img, prompt, save_metadata=save_metadata, extra_pnginfo=None):
|
||||
def save_image(self, image_path, img, prompt, save_metadata=save_metadata, extra_pnginfo=None, quality=75):
|
||||
# print(f"debug save_images: image_path={image_path}")
|
||||
output_ext = os.path.splitext(os.path.basename(image_path))[1]
|
||||
metadata = None
|
||||
kwargs = dict()
|
||||
|
||||
# TODO: see if convert_hdr_to_8bit=False make a change
|
||||
|
||||
# match is python 3.10+
|
||||
match output_ext:
|
||||
case '.avif':
|
||||
if output_ext in ['.avif']:
|
||||
if save_metadata: kwargs["exif"] = self.get_metadata_exif(img, prompt, extra_pnginfo)
|
||||
kwargs["lossless"] = self.lossless
|
||||
kwargs["quality"] = self.avif_quality
|
||||
case '.webp':
|
||||
kwargs["quality"] = quality
|
||||
if quality == 100: kwargs["lossless"] = True
|
||||
elif output_ext in ['.webp']:
|
||||
if save_metadata: kwargs["exif"] = self.get_metadata_exif(img, prompt, extra_pnginfo)
|
||||
kwargs["lossless"] = self.lossless
|
||||
kwargs["quality"] = self.webp_quality
|
||||
if self.webp_quality == 100: kwargs["lossless"] = True
|
||||
case '.jpg':
|
||||
kwargs["quality"] = quality
|
||||
if quality == 100: kwargs["lossless"] = True
|
||||
elif output_ext in ['.jpg', '.jpeg']:
|
||||
if save_metadata: kwargs["exif"] = self.get_metadata_exif(img, prompt, extra_pnginfo)
|
||||
kwargs["quality"] = self.jpeg_quality
|
||||
case '.jxl':
|
||||
kwargs["lossless"] = self.lossless
|
||||
kwargs["quality"] = quality
|
||||
kwargs["optimize"] = self.optimize_image
|
||||
elif output_ext in ['.jxl']:
|
||||
if save_metadata: kwargs["exif"] = self.get_metadata_exif(img, prompt, extra_pnginfo)
|
||||
kwargs["quality"] = self.jxl_quality
|
||||
case _:
|
||||
# png: no quality
|
||||
kwargs["quality"] = quality
|
||||
if quality == 100: kwargs["lossless"] = True
|
||||
elif output_ext in ['.tiff']:
|
||||
# tiff: i suspect no quality either
|
||||
kwargs["quality"] = quality
|
||||
kwargs["optimize"] = self.optimize_image
|
||||
elif output_ext in ['.png', '.gif']:
|
||||
# png/gif: no quality
|
||||
if save_metadata: kwargs["pnginfo"] = self.get_metadata_png(img, prompt, extra_pnginfo)
|
||||
kwargs["compress_level"] = self.png_compress_level
|
||||
# png
|
||||
kwargs["optimize"] = self.optimize_image
|
||||
# elif output_ext in ['.bmp']:
|
||||
# nothing to add
|
||||
|
||||
# img.save(image_path, pnginfo=metadata, compress_level=self.png_compress_level)
|
||||
img.save(image_path, **kwargs)
|
||||
@@ -547,6 +586,7 @@ class SaveImageExtended:
|
||||
positive_text_opt=None,
|
||||
extra_pnginfo=None,
|
||||
prompt=None,
|
||||
quality=75,
|
||||
):
|
||||
|
||||
# print(f"filename_prefix = x{filename_prefix}x")
|
||||
@@ -568,8 +608,9 @@ class SaveImageExtended:
|
||||
################################## UNCOMMENT HERE TO SEE THE ENTIRE PROMPT
|
||||
# pprint.pprint(prompt)
|
||||
##########################################################################
|
||||
custom_filename = self.generate_custom_name(filename_keys_to_extract, filename_prefix, delimiter, prompt)
|
||||
custom_foldername = self.generate_custom_name(foldername_keys_to_extract, foldername_prefix, delimiter, prompt)
|
||||
timestamp = datetime.now()
|
||||
custom_filename = self.generate_custom_name(filename_keys_to_extract, filename_prefix, delimiter, prompt, timestamp)
|
||||
custom_foldername = self.generate_custom_name(foldername_keys_to_extract, foldername_prefix, delimiter, prompt, timestamp)
|
||||
|
||||
# Get set resolution value
|
||||
i = 255. * images[0].cpu().numpy()
|
||||
@@ -598,17 +639,17 @@ class SaveImageExtended:
|
||||
file = f'{counter:0{counter_digits}}{delimiter}{filename}{output_ext}'
|
||||
|
||||
image_path = os.path.join(output_path, file)
|
||||
self.save_image(image_path, img, prompt, save_metadata, extra_pnginfo)
|
||||
self.save_image(image_path, img, prompt, save_metadata, extra_pnginfo, quality)
|
||||
|
||||
if save_job_data != 'disabled' and job_data_per_image:
|
||||
self.save_job_to_json(save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, f'{file.removesuffix(output_ext)}.json')
|
||||
self.save_job_to_json(save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, f'{file.removesuffix(output_ext)}.json', timestamp)
|
||||
|
||||
subfolder = self.get_subfolder_path(image_path, self.output_dir)
|
||||
results.append({ 'filename': file, 'subfolder': subfolder, 'type': self.type})
|
||||
counter += 1
|
||||
|
||||
if save_job_data != 'disabled' and not job_data_per_image:
|
||||
self.save_job_to_json(save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, 'jobs.json')
|
||||
self.save_job_to_json(save_job_data, prompt, filename_prefix, positive_text_opt, negative_text_opt, job_custom_text, resolution, output_path, 'jobs.json', timestamp)
|
||||
|
||||
except OSError as e:
|
||||
print(f"SaveImageExtended {version} error: An error occurred while creating the subfolder or saving the image: {e}")
|
||||
|
||||
Reference in New Issue
Block a user