From f8580e567d3012671cab41a5d31400c3bc4df936 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Mon, 23 Oct 2023 22:30:11 -0400 Subject: [PATCH] strip metadata with exiftool --- .../src/infra/repositories/media.repository.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/server/src/infra/repositories/media.repository.ts b/server/src/infra/repositories/media.repository.ts index b213644c9..a4e0b65e4 100644 --- a/server/src/infra/repositories/media.repository.ts +++ b/server/src/infra/repositories/media.repository.ts @@ -6,6 +6,7 @@ import fs from 'fs/promises'; import sharp from 'sharp'; import { Writable } from 'stream'; import { promisify } from 'util'; +import { exiftool, Tags, WriteTags } from 'exiftool-vendored'; const probe = promisify(ffmpeg.ffprobe); sharp.concurrency(0); @@ -26,20 +27,10 @@ export class MediaRepository implements IMediaRepository { } async resize(input: string | Buffer, output: string, options: ResizeOptions): Promise { - const buffer = await sharp(input, { failOn: 'none' }) + await sharp(input, { failOn: 'none' }) + .pipelineColorspace(options.colorspace === Colorspace.SRGB ? 'srgb' : 'rgb16') .resize(options.size, options.size, { fit: 'outside', withoutEnlargement: true }) .rotate() - .jxl({ lossless: true }) - .toBuffer(); - // A second sharp instance is required for the ICC profile, as all metadata - // is preserved otherwise. - // - // It should be possible to do this with a single sharp instance in future. - // See: https://github.com/lovell/sharp/issues/3824 - // - // TODO: Use a single sharp instance. - await sharp(buffer, { failOn: 'none' }) - .pipelineColorspace(options.colorspace === Colorspace.SRGB ? 'srgb' : 'rgb16') .withMetadata({ icc: options.colorspace }) .toFormat(options.format, { quality: options.quality, @@ -47,6 +38,8 @@ export class MediaRepository implements IMediaRepository { chromaSubsampling: options.quality >= 80 ? '4:4:4' : '4:2:0', }) .toFile(output); + + await exiftool.write(output, {EXIF: null} as any as WriteTags, ['-g', '-overwrite_original']); } async probe(input: string): Promise {