-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Errors when uploading certain pictures from my cell phone #3416
Comments
Should be fixed now. |
@shawnington I've just tested your update #3422. And interestingly, it works for PIL=10.2.0, but the very picture caused another error when using PIL=10.3.0. I think the tomato picture is weird, because the second frame is not the same as the first frame, I don't know why my Pixel 6's default camera save the photo this way, but it's real. Here is the error message:
And I found that the dimension of two frames are different: and I found that the 10.3.0 version == |
Its unfortunately going to be a tricky issue to keep up with, and Im sure our triage will break with different versions of PIL, as its not an actual comfy bug, its a work around for a fairly long standing PIL bug. Id recommend using the version that works, and maybe we should looking into including version 10.2.0 in the requirements.txt so long as it doesn't break additional functionality. Im going to do some more digging, and see if there is a more robust way to solve this, as photos from phones are quite a common input, for myself as well. I take pictures with my phone that I wan't to re-imagine into something cool, so I understand your frustration. Can you by chance provide the make model and software version for the phone you are have errors with? There is always a small chance that there is a known bug with the phone that is causing errors. The commit took the fix Comfy contributed and merged it into a generalized fix for embedded ICC profiles in PNGs being interpreted as decompression attacks, as they both used the exact same solution to resolve the issue. So it just made it a wrapper function that you can pass any PIL function that is impacted by that kind of bug into. I'm going to have to look into the differences between pillow 10.3.0 and 10.2.0, maybe it will elucidate an actual reason the bug is happening. |
Maybe we need to spec as |
For the app: My phone is Pixel 6, manufactured in 2021 with hardware version MP1.0. |
Thats actually much more reasonable, as long as we confirm its just isolated to 10.3.0 Im not super familiar with the proper format to spec requirements.txt for something like this, would you want to commit the change? If not I'll figure it out and commit it. |
I just digged into the camera's settings, and I found that if I disable the Ultra HDR feature (which was enabled by default), I get only one frame! Here's the documentation of this feature (with it's format JPEG_R!): |
And follow this lead, I found this issue from PIL: Yes, they need to support that to solve this issue. |
I actually was about to post a follow up question about that. There is an outstanding issue having to do with HDR images that looked very similar to yours, where a smaller image that appeared to be encoding exposure data was included in a similar format, it seems to be limited to android currently. It's definitely a PIL issue, I'll update with the issue number when I find it. |
You beat me to it, but so are you saying that it works with your Ultra HDR images in 10.2.0 and not 10.3.0? Or does it not work with the those images in either? |
I'll downgrade my PIL for now. Everything works for 10.2.0. Thanks @shawnington and @ltdrdata . |
Thanks, @ltdrdata do you want to commit the Pillow!=10.3.0 as you have more experience with requirements.txt than me or should I? |
I just made a PR. |
@shawnington , it doesn't cause problem because PIL 10.2.0 recognizes the Ultra HDR image as two frames with the same resolution. I think it is a reasonable assumption because how can two frames be different even if it was a video? So when PIL 10.2.0 was used, I have this: As long as I ONLY use the FIRST frame in the workflow, there's no error. PIL 10.3.0 changes this assumption, and returns the "right" resolution of the second frame, which is smaller by JPEG_R format, and that causes the |
Okay, interesting. There should definitely be multiple ways to work around that, either discarding the second frame if its not the same size, resizing the second frame so touch.cat doesn't fail, etc.
This seems to be the offending code. it seems with most standards for HDR the exposure data is a small thumbnail when processed correctly. Maybe there needs to be a check for matching dimensions and discard the extra images if they are there. Im not sure what the desired behavior is, obviously a loading of the image type as a single image is preferable, but I don't think we are going to be able to get the processing done with the HDR intent intact. |
…s are included in when HDR images are loaded. Added an image dimension check with a blocking if statement in ImageSequence iterator that prevents images that do not match the size of the first image added to the output_images list from being appended.
…tional smaller images. Added a blocking if statement in the ImageSequence.Iterator that checks if subsequent images after the first match dimensionally, and prevent them from being appended to output_images if they do not match. This does not fix or change current behavior for PIL 10.2.0 where the images are loaded at the same size, but it does for 10.3.0 where they are loaded at their correct smaller sizes.
This commit should fix this issue for both PIL 10.2 and 10.3 Feel free to add this to your local branch to test as it's not yet merged.
|
#3454) * Fix to LoadImage Node for #3416 HDR images loading additional smaller images. Added a blocking if statement in the ImageSequence.Iterator that checks if subsequent images after the first match dimensionally, and prevent them from being appended to output_images if they do not match. This does not fix or change current behavior for PIL 10.2.0 where the images are loaded at the same size, but it does for 10.3.0 where they are loaded at their correct smaller sizes. * added list of excluded formats that should return 1 image added an explicit check for the image format so that additional formats can be added to the list that have problematic behavior.
@liusida check the latest commit, it should resolve all of your issue. If so, this issue can be marked closed. Thanks for your detailed reporting and contribution in figuring out what was actually causing the problem. The issue is now resolved for me for every PIL version I have tried with your supplied images, I tested down to 9.5.0 |
Now it works perfectly for me locally. Only the primary images show up. Thanks for the update! |
…tional smaller… (comfyanonymous#3454) * Fix to LoadImage Node for comfyanonymous#3416 HDR images loading additional smaller images. Added a blocking if statement in the ImageSequence.Iterator that checks if subsequent images after the first match dimensionally, and prevent them from being appended to output_images if they do not match. This does not fix or change current behavior for PIL 10.2.0 where the images are loaded at the same size, but it does for 10.3.0 where they are loaded at their correct smaller sizes. * added list of excluded formats that should return 1 image added an explicit check for the image format so that additional formats can be added to the list that have problematic behavior.
When I try to use ComfyUI on my cell phone (Android), sometimes, when I try to upload an image, it will give error like this:
And when I paused the process right before the error happens, and I inspect the variable
img
, I saw this (withn_frames
=2), but it's a JPG! I don't know why, and ChatGPT says that it's a MPO file.Extracted with ChatGPT:
I never encounter this kind of JPGs on my Desktop, ether Ubuntu or Windows. I'm not sure why cell phones store some JPGs like that (no all JPGs have two frames, only some of them do). But this causes errors in ComfyUI's LoadImage node.
I'll try to upload one of the JPG files here in the comment. To reproduce the error, save the tomato photo and try to upload with ComfyUI's
Load Image
node.The text was updated successfully, but these errors were encountered: