mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: resolve 7 bugs from QA sweep (#208)
- Fix selective metadata stripping (P1): use Sharp's keepExif()/keepIccProfile()
instead of broken withMetadata({}) that preserved everything
- Fix meme font mapping (P1): add ArchivoBlack and ComicNeue fonts, map
arial-black and comic-sans to correct TTF files instead of Anton
- Fix meme contentType (P2): detect actual output format from Sharp metadata
instead of hardcoding image/png
- Fix info/text-overlay/color-palette i18n (P2): wire up existing translation
keys that were imported but never used
- Fix info and color-palette displayMode (P2): change from before-after to
no-comparison since neither tool produces a processed image
- Add missing i18n keys across all 21 locales
- Update displayMode test assertions
This commit is contained in:
@@ -6,7 +6,6 @@ export async function stripMetadata(
|
||||
): Promise<Sharp> {
|
||||
const { stripExif, stripGps, stripIcc, stripXmp, stripAll } = options;
|
||||
|
||||
// Default behavior: strip all metadata
|
||||
const shouldStripAll =
|
||||
stripAll === true ||
|
||||
(stripExif === undefined &&
|
||||
@@ -16,23 +15,28 @@ export async function stripMetadata(
|
||||
stripAll === undefined);
|
||||
|
||||
if (shouldStripAll) {
|
||||
// withMetadata({}) with no options strips everything;
|
||||
// but to truly strip we avoid calling withMetadata at all.
|
||||
// Sharp strips metadata by default when outputting.
|
||||
// Calling .withMetadata() KEEPS metadata, so we do NOT call it.
|
||||
return image;
|
||||
}
|
||||
|
||||
// Selective stripping: we keep metadata but remove specific fields.
|
||||
// Sharp's withMetadata lets us keep ICC, EXIF, etc.
|
||||
// We call withMetadata to keep what wasn't requested stripped.
|
||||
const keepIcc = !stripIcc;
|
||||
const strippingNothing = !stripExif && !stripGps && !stripIcc && !stripXmp;
|
||||
if (strippingNothing) {
|
||||
return image.withMetadata();
|
||||
}
|
||||
|
||||
return image.withMetadata({
|
||||
// If we want to keep ICC, pass undefined (Sharp default keeps it with withMetadata)
|
||||
// If we want to strip ICC, we need to not call withMetadata at all or handle differently
|
||||
// Sharp's withMetadata keeps metadata; without it, metadata is stripped.
|
||||
// For selective stripping, we strip all first then re-add what we want to keep.
|
||||
...(keepIcc ? {} : {}),
|
||||
});
|
||||
// Selective stripping: Sharp strips all metadata by default (no calls needed).
|
||||
// We chain keepExif() / keepIccProfile() to preserve categories the user
|
||||
// does NOT want stripped.
|
||||
let pipeline = image;
|
||||
|
||||
if (!stripExif && !stripGps) {
|
||||
pipeline = pipeline.keepExif();
|
||||
}
|
||||
|
||||
if (!stripIcc) {
|
||||
pipeline = pipeline.keepIccProfile();
|
||||
}
|
||||
|
||||
// XMP: Sharp has no keepXmp() method. XMP is always stripped in selective mode.
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user