Preserve EXIF metadata when re-encoding images to JPEG#53
Open
ascpixi wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Preserves EXIF metadata when images are re-encoded to JPEG, both on the client (after canvas-based compression in compressToJpeg) and on the server (by telling Active Storage's variant pipeline not to strip metadata). The client-side helpers extract the original APP1/EXIF segment, reset the Orientation tag to 1 (since canvas already baked rotation into pixels), and splice the segment into the canvas-produced JPEG.
Changes:
- Add three JS helpers (
extractJpegExif,patchExifOrientation,spliceExifIntoJpeg) and wire them intocompressToJpegso re-encoded JPEGs retain original EXIF with orientation reset. - Pass
saver: { strip: false }to everyresize_to_limitvariant call across admin and public views so server-side variants also keep EXIF.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| app/javascript/application.js | Adds EXIF extract/patch/splice helpers and integrates them into the post-canvas JPEG path. |
| app/views/active_storage/blobs/_blob.html.erb | Adds saver: { strip: false } to the default blob representation variant. |
| app/views/admin/check_ins/index.html.erb | Adds saver: { strip: false } to the 80×80 check-in thumbnail variant. |
| app/views/admin/check_ins/show.html.erb | Adds saver: { strip: false } to the 800×800 check-in image variant. |
| app/views/admin/submissions/_table.html.erb | Adds saver: { strip: false } to the 64×64 submission thumbnail variant. |
| app/views/admin/submissions/index.html.erb | Adds saver: { strip: false } to the 160×160 and 64×64 submission variants. |
| app/views/admin/submissions/show.html.erb | Adds saver: { strip: false } to the 48×48 submission variant. |
| app/views/static_pages/home.html.erb | Adds saver: { strip: false } to the 120×120 zone-first-submission variant. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+10
to
+21
| function extractJpegExif(srcBytes) { | ||
| var i = 2; // skip SOI FF D8 | ||
| while (i + 3 < srcBytes.length) { | ||
| if (srcBytes[i] !== 0xFF) break; | ||
| var marker = srcBytes[i + 1]; | ||
| var segLen = (srcBytes[i + 2] << 8) | srcBytes[i + 3]; | ||
| if (marker === 0xE1) return srcBytes.slice(i, i + 2 + segLen); // APP1 | ||
| if (marker === 0xDA || marker === 0xD9) break; // SOS / EOI | ||
| i += 2 + segLen; | ||
| } | ||
| return null; | ||
| } |
| } | ||
| patchExifOrientation(exif, 1); | ||
| var finalBlob = spliceExifIntoJpeg(exif, new Uint8Array(bufs[1])); | ||
| resolve(new File([finalBlob], name, { type: "image/jpeg", lastModified: Date.now() })); |
Comment on lines
+36
to
+43
| for (var j = 0; j < n; j++) { | ||
| var e = ifd + 2 + j * 12; | ||
| if (r16(e) === 0x0112) { // Orientation tag | ||
| if (le) { app1[e+8] = value & 0xFF; app1[e+9] = 0; } | ||
| else { app1[e+8] = 0; app1[e+9] = value & 0xFF; } | ||
| return; | ||
| } | ||
| } |
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.
Copy EXIF from source JPEG into canvas-reencoded output; reset orientation tag to avoid double-rotation. Add
saver: { strip: false }to all Active Storage variants.