Tiff: allow writing floating point tag values#1113
Tiff: allow writing floating point tag values#1113hugovk merged 6 commits intopython-pillow:masterfrom
Conversation
Use the inverse logic used for loading floating point tag values to also write them out again.
|
@bpedersen2 Please can you add tests so this new code is covered? https://coveralls.io/builds/1976951/source?filename=PIL%2FTiffImagePlugin.py#L520 |
Add tests for writing of float/double values in tiff file tags.
due to rounding, the values are just 'almost' equal.
|
Noting that this likely interacts with #1059. |
|
@bpedersen2 Any progress on this? |
|
This is great! I was just about to add a new issue on exactly the same. I had inserted my own custom code in TiffImagePlugin.py similar to @bpedersen2 but I like his code better. Especially since it looks like the Travis CI tests passed I really hope there is nothing left in the way for this pull request to be merged. As evidenced by #983 and this post I think there is considerable interest from GIS developers in using Pillow to save GeoTIFFs (or at least there could and should be). And since #660 has demonstrated how to save custom TIFF tags, the inability to save float/double tags is really the last remaining obstacle to having fully blown support for GeoTIFF images in Pillow, since virtually all of the important GIS-specific tags (coordinate transform and projection definitions) in the GeoTIFF specification require decimal numbers of type double. I have a GIS developers book coming out soon where I patch Pillow to support Python floats and then use it to save GeoTIFFs, so it would be especially great if this feature was already in the main branch so I can drop the part about patching. This could be a great encouragement to GIS developers and users to know that Pillow has at least basic out-of-the-box support for GeoTIFF. If there is anything I could do to speed the process I would gladly do so. |
|
Looks good to me, merging. @karimbahgat Do you think it'd be useful to add any more tests for GIS-specific tags? |
Tiff: allow writing floating point tag values
|
That was fast, thanks! Regarding the GIS tag tests, I don't think there would be a point. The GIS specific tags are just like any other tag, and since @bpedersen2 added successfull tests of saving floats and doubles to some generic tags, those tests apply equally much to any GIS-specific tags or any other specialized-tag for that matter. Or maybe I misunderstood? I can testify that I was able to successfully save and reload a GeoTIFF of the world with the new Pillow code after your merge. The commonly used GIS-specific "nodata" tag was also successfully saved and reloaded as ascii type. I think all of the GIS-tags only use short, double, or ascii types so they should all be supported. There is however one tag that contains a nodata image mask of sorts but I haven't looked into which data type it uses. For another time I think :P |
|
You understood :) |
Use the inverse logic used for loading floating point tag
values to also write them out again.