Skip to content

Fix exported JPEG EXIF so ExifTool can rewrite tags by stripping stale RAW preview SubIFD pointers.#404

Merged
marcinz606 merged 2 commits into
marcinz606:mainfrom
jboneng:fix/EXIF_Export
Jul 5, 2026
Merged

Fix exported JPEG EXIF so ExifTool can rewrite tags by stripping stale RAW preview SubIFD pointers.#404
marcinz606 merged 2 commits into
marcinz606:mainfrom
jboneng:fix/EXIF_Export

Conversation

@jboneng

@jboneng jboneng commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes exported JPEG EXIF so third-party tools (notably ExifTool) can read and rewrite metadata tags.

When exporting from RAW, NegPy preserved the source EXIF via piexif, including IFD0 tags from the camera's embedded preview/thumbnail (SubIFDs, StripOffsets, preview dimensions, etc.). Those offsets are valid inside the multi-MB RAW file but invalid in a standalone JPEG APP1 block. ExifTool then failed with "Can't read SubIFD data" (and sometimes "Error reading StripOffsets data in IFD0") when writing tags such as -UserComment=foo.

Before serializing JPEG EXIF, _prepare_jpeg_exif() now strips preview-only IFD0 tags and clears the thumbnail/1st IFD, while keeping real metadata.

Test plan

  • uv run pytest tests/test_metadata_writer.py tests/metadata/test_writer.py -v
  • test_embed_strips_raw_preview_ifd_tags_from_jpeg — synthetic RAW-like EXIF; stale tags absent, Make/FocalLength preserved
  • test_embed_jpeg_exiftool_can_write_user_comment — synthetic RAW-like EXIF (SubIFDs/StripOffsets); ExifTool -UserComment=foo succeeds (skips if exiftool not installed)
  • Manual: export JPEG from NEF → exiftool -UserComment=foo _JMB5113.jpg1 image files updated (no SubIFD error)
  • Confirm Make/Model/exposure tags still present on exported JPEGs after fix

Fixes #402

@marcinz606 marcinz606 merged commit fe4d18f into marcinz606:main Jul 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NegPy appears to corrupt EXIF data on export

2 participants