fix: Image.metadata() missing camera-specific Exif sub-IFD tags - #91
Merged
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Image.getexif() (the modern public Pillow API) only returns the
top-level IFD0 tags (Make, Model, Orientation, ...). Camera-specific
tags -- FocalLength, ExposureTime, FNumber, ISOSpeedRatings, LensModel,
etc. -- live in a separate "Exif" sub-IFD that getexif() does not
flatten in. metadata() never fetched that sub-IFD, so
img.metadata("FocalLength") always raised KeyError even though the
tag is genuinely present in the file (confirmed via raw PIL: it's
under Exif.get_ifd(0x8769), the fixed EXIF-spec tag id for the Exif
IFD pointer).
This is a Pillow API evolution, not a data problem: the old private
Image._getexif() used to flatten everything into one dict; the public
getexif() introduced later deliberately does not, requiring an
explicit get_ifd() call for the sub-IFD.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
petercorke
force-pushed
the
fix/metadata-exif-subifd
branch
from
August 16, 2026 01:27
358ba44 to
d554ef2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Image.metadata("FocalLength")(andExposureTime,FNumber,ISOSpeedRatings,LensModel, ...) always raisedKeyError, even though the tag is genuinely present in the file.Image.getexif()(the modern public Pillow API) only returns the top-level IFD0 tags (Make,Model,Orientation, ...). Camera-specific tags live in a separate "Exif" sub-IFD thatgetexif()does not flatten in -- needs an explicitExif.get_ifd(0x8769)call (0x8769is the fixed EXIF-spec tag id for the Exif IFD pointer).Image._getexif()used to flatten everything into one dict; the publicgetexif()deliberately does not.Test plan
tests/test_image_io.py::TestImage::test_metadata-- was a stub (pass), now exercises both top-level (Make,Model) and sub-IFD (FocalLength,FNumber) tags against the bundledwalls-l.pngfixture (real iPhone 5s EXIF data)f = walls_l.metadata("FocalLength"),f = notredame.metadata("FocalLength"))🤖 Generated with Claude Code