Commit Graph

6 Commits

Author SHA1 Message Date
comfyanonymous c75b50607b Less confusing exception if pillow() function fails. 2024-07-29 11:15:37 -04:00
Thomas Ward c5a48b15bd
Make default hash lib configurable without code changes via CLI argument (#3947)
* cli_args: Add --duplicate-check-hash-function.

* server.py: compare_image_hash configurable hash function

Uses an argument added in cli_args to specify the type of hashing to default to for duplicate hash checking.  Uses an `eval()` to identify the specific hashlib class to utilize, but ultimately safely operates because we have specific options and only those options/choices in the arg parser.  So we don't have any unsafe input there.

* Add hasher() to node_helpers

* hashlib selection moved to node_helpers

* default-hashing-function instead of dupe checking hasher

This makes a default-hashing-function option instead of previous selected option.

* Use args.default_hashing_function

* Use safer handling for node_helpers.hasher()

Uses a safer handling method than `eval` to evaluate default hashing function.

* Stray parentheses are evil.

* Indentation fix.

Somehow when I hit save I didn't notice I missed a space to make indentation work proper.  Oops!
2024-07-16 18:27:09 -04:00
shawnington 0fecfd2b1a
Added generic wrapper function node_helpers.pillow to fix PIL issues #4472 and #2445 (#3422)
* Update node_helpers.py to use generic pillow wrapper to resolve multiple meta-data related issues.

replaced open_image function with a generic pillow function that takes Pil functions as a dependency injection and applies the ImageFile.LOAD_TRUNCATED_IMAGES try except fix to them. 

This provides an extensible function to handle related errors that can wrap offending functions when discovered without the need to repeat code.

* Update a few Pil functions to use node_helpers.pillow wrapper

Update a Pil function calls in a few locations to use the generic node_helpers.pillow wrapper that takes the function as a dependency injection and uses the try except method with ImageFIle.LOAD_TRUNCATED_IMAGES solution

* Corrected comment in issue #s fixed.

* Update node_helpers.py to remove import of Image from PIL

import of Image is no longer required as functions are Injected
2024-05-09 05:38:00 -04:00
comfyanonymous 72508a8d19 Only set LOAD_TRUNCATED_IMAGES when if the Image open fails.
Document which PIL issues this works around.
2024-05-04 03:51:03 -04:00
shawnington 0d45efb7d6
Fixed Issue with LoadImage node when loading PNG files with embedded ICC profiles. (#3316)
* Fix issue with how PIL loads small PNG files nodes.py

Added flag to prevent ValueError: Decompressed Data Too Large
when loading PNG images with large meta data such as large embedded color profiles

* Update LoadImage node to fix error when loading PNG's in nodes.py

Fixed Value Error: Decompressed Data Too Large thrown by PIL when attempting to opening PNG files with large embedded ICC colorspaces by setting the follow flag to true when loading png images:  ImageFile.LOAD_TRUNCATED_IMAGES = True

* Update node_helpers.py to include open_image helper function

open_image includes try except to catch Pillow Value Errors that occur when large ICC profiles are embedded in images.

* Update LoadImage node to use open_image helper function inplace of Image.open

open_image helper function in node_helpers.py  fixes a Pillow error when attempting to open images with large embedded ICC profiles by adding an exception handler to load the image with truncated meta data if regular loading is not possible.
2024-05-04 03:32:41 -04:00
comfyanonymous 80bda6c163 Cleanup a few conditioning nodes. 2024-04-07 14:27:40 -04:00