mirror of
https://github.com/wiltodelta/remove-ai-watermarks.git
synced 2026-10-14 21:40:47 +02:00
Issue #98. cv2's encoders write no container metadata, so every pixel-path output (all, visible, invisible, erase) came back without its colour profile and orientation tag, even with --keep-metadata. imwrite now takes display_tags_from, the file whose decode produced the pixels, and restores the two display tags into the re-encoded output: PNG and JPEG by splicing iCCP/eXIf chunks and APP1/APP2 segments into the encoded bytes, WebP by a lossless Pillow re-save (libwebp hides hand-spliced chunks from readers without a VP8X header), HEIF through the save call itself. Orientation is re-tagged only when the raster still has the source's stored dimensions: cv2 rotates JPEG and (build-dependent) PNG decodes under IMREAD_COLOR but never IMREAD_UNCHANGED, which is what the pixel paths read with, so the decision is made against the raster's own shape and cannot double-rotate. The default metadata strip now preserves what the restore put back: the PIL path forwards the profile and a scrubbed EXIF (orientation included) for PNG and WebP outputs, the 16-bit chunk walker re-emits eXIf scrubbed instead of dropping it wholesale, and --remove-all actually drops the ICC profile on every format (Pillow's saver fallback kept it alive, contradicting the documented "removed by --remove-all"). Mirror and 180-degree orientations (2, 3, 4) stay untagged: no cheap signal distinguishes a rotated decode from a stored one for them.