Skip to content

Preserve EXIF metadata when re-encoding images to JPEG#53

Open
ascpixi wants to merge 2 commits into
mainfrom
feat/preserve-exif-on-jpeg-reencoding
Open

Preserve EXIF metadata when re-encoding images to JPEG#53
ascpixi wants to merge 2 commits into
mainfrom
feat/preserve-exif-on-jpeg-reencoding

Conversation

@ascpixi

@ascpixi ascpixi commented May 24, 2026

Copy link
Copy Markdown
Member

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into compressToJpeg so re-encoded JPEGs retain original EXIF with orientation reset.
  • Pass saver: { strip: false } to every resize_to_limit variant 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 thread app/javascript/application.js Outdated
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;
}
Comment thread app/javascript/application.js Outdated
}
patchExifOrientation(exif, 1);
var finalBlob = spliceExifIntoJpeg(exif, new Uint8Array(bufs[1]));
resolve(new File([finalBlob], name, { type: "image/jpeg", lastModified: Date.now() }));
Comment thread app/javascript/application.js Outdated
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;
}
}
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.

2 participants