Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added generic wrapper function node_helpers.pillow to fix PIL issues #4472 and #2445 #3422

Merged
merged 4 commits into from
May 9, 2024

Conversation

shawnington
Copy link
Contributor

Created a generic wrapper function node_helpers.pillow, that takes PIL functions as a dependency injection to apply the try except solution of using ImageFile.LOAD_TRUNCATED_IMAGES = True to fix PIL issues #4472 and #2445

The fix for ComfyUI issue #3416 is re-implemented using the generalized function

Additionally, the calls to Image.open and ImageOps.exif_transpose have be updated in a few nodes the new generic wrapper function node_helpers.pillow

This gives us a single place to handle meta data related pil errors, and apply fixes without having to duplicate code in other locations. It also provides an easy to use generic wrapper for node creators to use as a way to handle pil errors that fixes have been found for.

the function is called as follows:

img = node_helpers.pillow(Image.open, image_path)
i = node_helpers.pillow(ImageOps.exif_transpose, i)

…ple 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 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
@comfyanonymous comfyanonymous merged commit 0fecfd2 into comfyanonymous:master May 9, 2024
1 check passed
Lin1031 pushed a commit to Lin1031/ComfyUI that referenced this pull request May 14, 2024
…#4472 and comfyanonymous#2445 (comfyanonymous#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants