Moustikitos / tyf

Manipulate EXIF and IFD metadata.
19 stars 8 forks source link

Issue with saving #14

Closed seanliu-oss closed 3 years ago

seanliu-oss commented 3 years ago

Hi there,

I am guessing this is a recurrence of previous issues. This is a simple code: import numpy as np import Tyf import tifffile as tiff

filename="Test.tif" outputname="output.tif"

img = tiff.imread(filename) exif_info = Tyf.open(filename)

tiff.imsave(outputname, img) exif_info.save(outputname)

And I got following error: Traceback (most recent call last): File "J:/notebook/simple_test_exif.py", line 12, in exifinfo.save(outputname) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf__init.py", line 352, in save next_ifd = to_buffer(i, fileobj, nextifd, byteorder) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf__init.py", line 252, in to_buffer next_ifdoffset = dump(obj, fileobj, offset, byteorder) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf__init.py", line 250, in dump dump(getattr(i, "%s"%tag), f, i.get(tag).value[0], b) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf\init__.py", line 251, in dump return _writeIFD(i,f,o,b) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf\init__.py", line 162, in _writeIFD pack(byteorder+fmt, fileobj, value) File "C:\Users\sean\AppData\Local\Programs\Python\Python37\lib\site-packages\Tyf\init__.py", line 14, in pack = lambda fmt, fileobj, value: fileobj.write(struct.pack(fmt, *value)) struct.error: ubyte format requires 0 <= number <= 255

I've also attached the zipped TIF file for your reference. Could you please take a look?

Thanks, Sean

test.zip

Moustikitos commented 3 years ago

Hi,

I'l having a look to this issue right now. Was workin on two other projects giving me hard time.

Thank for the report.

Moustikitos commented 3 years ago

Hi,

I just did a test with your Tif

>>> t = Tyf.open("test/issue #14.tif") 
<IFD tag RowsPerStrip:None>: EncodingException('4294967295 not in range [0:256[')
>>> t.save("output.tif")
<IFD tag StripOffsets:27706>: EncodingException('27593 not in range [0:256[')

output.tif is a valid tif file. Did you get last version of Tyf ? (ie Github) Looks like StripOffset type is not correct, should not be Byte type... I'll have a look @ it.

Moustikitos commented 3 years ago

Ok,

I had a better look to my code : StripOffset is either a Byte or a Long. Code automatically switches to correct type. Tell me if your issue still there with a clone of git repo.

Thanks.

seanliu-oss commented 3 years ago

Sorry haven't got a chance testing this. Will test and report back.

seanliu-oss commented 3 years ago

Hi, Installed the latest version (1.4.2) by cloning the git repo. The saving seems to work properly in spite of the exceptions. So I'll consider this issue closed, but it would be nicer if the messages get cleaned up.

: EncodingException('4294967295 not in range [0:256[') : EncodingException('318 not in range [0:256[') Thanks, Sean