Skip to content

Take TIFF geometry tags from the image when saving - #10366

Open
aclark4life wants to merge 2 commits into
mainfrom
libtiff-geometry-tags
Open

aclark4life wants to merge 2 commits into
mainfrom
libtiff-geometry-tags

Conversation

@aclark4life

@aclark4life aclark4life commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

When saving a TIFF with libtiff, only BitsPerSample was taken from the image. ImageWidth, ImageLength, SamplesPerPixel and PlanarConfiguration could be overridden by tiffinfo, exif or the IFD of the original file.

This PR sets all of these tags from the image before the tiffinfo/exif merge, so the saved file always matches the image. test_geometry_tags now checks that the saved image is unchanged, rather than that the save is rejected, and covers ImageLength and PlanarConfiguration as well.

When saving with libtiff, only BITSPERSAMPLE was taken from the image.
IMAGEWIDTH, IMAGELENGTH, SAMPLESPERPIXEL and PLANAR_CONFIGURATION could
be overridden by tiffinfo, exif or the original file's IFD. Since
ec5f1cb, values describing a larger row than the image raise an
OSError; other values could still produce an invalid file. Use the
image's geometry for all of these tags instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@radarhere

radarhere commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

If the concern is that it could 'read past the end of the row buffer', then #10226 will raise an error from C for the SAMPLESPERPIXEL test.

If the argument is that we know what is correct, and the user shouldn't be able to shoot themselves in the foot by overriding these settings, then I think that argument applies when saving without libtiff as well.

I've pushed a commit to prevent the user from overriding PLANAR_CONFIGURATION and SAMPLESPERPIXEL when saving without libtiff as well. I'd like to do the same to IMAGEWIDTH and IMAGELENGTH, but #7650 prevented that.

@radarhere radarhere changed the title Take libtiff geometry tags from the image when saving Take TIFF geometry tags from the image when saving Oct 31, 2026
@radarhere
radarhere force-pushed the libtiff-geometry-tags branch from 3a03997 to cae0858 Compare October 31, 2026 09:31
@radarhere
radarhere force-pushed the libtiff-geometry-tags branch from cae0858 to 2983d48 Compare October 31, 2026 09:47

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants