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
Support for a "blank" exif #6123
Comments
Thanks for your reply and PR!! 👏👏👏👏 |
I have an error "Error: not a TIFF file (header b"b'Exif\x" not valid)" with Pillow 9.2.0. |
@leakyH
|
hi @a-l-e-x-d-s-9 , I got a 404 error when open your image link, but I found that in this issue AUTOMATIC1111/stable-diffusion-webui#7034 (comment), a b"b'Exif\x" was also met and seemed to be corrected
. Maybe you come here from this issue LOL. Line 3549 in 58acec3
So I think the extra b' in b"b'Exif\x" was added in somewhere else by mistake(maybe the mentioned webui repo or xformers? ), and then read by Pillow.
|
Lines 3521 to 3532 in 58acec3
@a-l-e-x-d-s-9 , in the first two lines, if the data starts with b"Exif\x00\x00", it will be stripped. But your image seems to have a extra b' , so the first 8 byte in data was then passed to TiffImagePlugin.ImageFileDirectory_v2 function. So it's not acceptedPillow/src/PIL/TiffImagePlugin.py Lines 259 to 270 in 58acec3
|
@leakyH |
Ok, I'm not sure if it's the best way to remove exif, but this is what I have found, and it is working: img = Image.open(open(file_path, 'rb'))
image_data = list(img.getdata())
image_without_exif = Image.new(img.mode, img.size)
image_without_exif.putdata(image_data)
img.close()
image_without_exif.save(file_path)
image_without_exif.close() |
where did you fund it? where we shoud correct code? |
I don't think that EXIF data should be saved by default with Pillow, so the question of how to remove it is strange to me. If you have an example where it is automatically present in a saved file, feel free to share. |
What did you do?
load a image and its exif is b'Exif\x00\x00'
What did you expect to happen?
Nothing to be done. Since functions like
ImageOps.exif_transpose
callsim.getexif()
, so I will expect that no errors should be raised.What actually happened?
the
getexif()
function will call Exif() to initiate a blank Exif instance, since the im._exif is None. And then the Exif() instance will load the im.info.get('exif'), which isb'Exif\x00\x00'
. In the load function, theb'Exif\x00\x00'
will be dropped by this line. So ab''
is passed toTiffImagePlugin.ImageFileDirectory_v2(self.head)
. And sinceb''
is not accepted byTiffImagePlugin.ImageFileDirectory_v2
, an error will be raised.BTW, these three lines in Exif.load():
make the code work when calling im.getexif() the second time.
What are your OS, Python and Pillow versions?
I wonder if this repo is considering returning a blank Exif in this case, instead of raising an error. I have no idea whether this would lead to other unknown damages or not.
The text was updated successfully, but these errors were encountered: