Compare commits
12 commits
main
...
4382-thumb
Author | SHA1 | Date | |
---|---|---|---|
|
f8580e567d | ||
|
f140da2ca1 | ||
|
4c1cac71c9 | ||
|
18889753b2 | ||
|
d14e686f60 | ||
|
770ac0063e | ||
|
4c56ef0526 | ||
|
259ed35b62 | ||
|
276eb43196 | ||
|
0a25d50822 | ||
|
beb2a48339 | ||
|
c647385847 |
4 changed files with 115 additions and 2 deletions
|
@ -6,6 +6,7 @@ import fs from 'fs/promises';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import { Writable } from 'stream';
|
import { Writable } from 'stream';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
import { exiftool, Tags, WriteTags } from 'exiftool-vendored';
|
||||||
|
|
||||||
const probe = promisify<string, FfprobeData>(ffmpeg.ffprobe);
|
const probe = promisify<string, FfprobeData>(ffmpeg.ffprobe);
|
||||||
sharp.concurrency(0);
|
sharp.concurrency(0);
|
||||||
|
@ -26,14 +27,19 @@ export class MediaRepository implements IMediaRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
async resize(input: string | Buffer, output: string, options: ResizeOptions): Promise<void> {
|
async resize(input: string | Buffer, output: string, options: ResizeOptions): Promise<void> {
|
||||||
const chromaSubsampling = options.quality >= 80 ? '4:4:4' : '4:2:0'; // this is default in libvips (except the threshold is 90), but we need to set it manually in sharp
|
|
||||||
await sharp(input, { failOn: 'none' })
|
await sharp(input, { failOn: 'none' })
|
||||||
.pipelineColorspace(options.colorspace === Colorspace.SRGB ? 'srgb' : 'rgb16')
|
.pipelineColorspace(options.colorspace === Colorspace.SRGB ? 'srgb' : 'rgb16')
|
||||||
.resize(options.size, options.size, { fit: 'outside', withoutEnlargement: true })
|
.resize(options.size, options.size, { fit: 'outside', withoutEnlargement: true })
|
||||||
.rotate()
|
.rotate()
|
||||||
.withMetadata({ icc: options.colorspace })
|
.withMetadata({ icc: options.colorspace })
|
||||||
.toFormat(options.format, { quality: options.quality, chromaSubsampling })
|
.toFormat(options.format, {
|
||||||
|
quality: options.quality,
|
||||||
|
// this is default in libvips (except the threshold is 90), but we need to set it manually in sharp
|
||||||
|
chromaSubsampling: options.quality >= 80 ? '4:4:4' : '4:2:0',
|
||||||
|
})
|
||||||
.toFile(output);
|
.toFile(output);
|
||||||
|
|
||||||
|
await exiftool.write(output, {EXIF: null} as any as WriteTags, ['-g', '-overwrite_original']);
|
||||||
}
|
}
|
||||||
|
|
||||||
async probe(input: string): Promise<VideoInfo> {
|
async probe(input: string): Promise<VideoInfo> {
|
||||||
|
|
|
@ -36,4 +36,18 @@ export const assetApi = {
|
||||||
expect(status).toBe(201);
|
expect(status).toBe(201);
|
||||||
return body as AssetFileUploadResponseDto;
|
return body as AssetFileUploadResponseDto;
|
||||||
},
|
},
|
||||||
|
getWebpThumbnail: async (server: any, accessToken: string, assetId: string) => {
|
||||||
|
const { body, status } = await request(server)
|
||||||
|
.get(`/asset/thumbnail/${assetId}`)
|
||||||
|
.set('Authorization', `Bearer ${accessToken}`);
|
||||||
|
expect(status).toBe(200);
|
||||||
|
return body;
|
||||||
|
},
|
||||||
|
getJpegThumbnail: async (server: any, accessToken: string, assetId: string) => {
|
||||||
|
const { body, status } = await request(server)
|
||||||
|
.get(`/asset/thumbnail/${assetId}?format=JPEG`)
|
||||||
|
.set('Authorization', `Bearer ${accessToken}`);
|
||||||
|
expect(status).toBe(200);
|
||||||
|
return body;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
91
server/test/e2e/metadata.e2e-spec.ts
Normal file
91
server/test/e2e/metadata.e2e-spec.ts
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
import { AssetResponseDto, LoginResponseDto } from '@app/domain';
|
||||||
|
import { AssetController } from '@app/immich';
|
||||||
|
import { INestApplication } from '@nestjs/common';
|
||||||
|
import { api } from '@test/api';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IMMICH_TEST_ASSET_PATH,
|
||||||
|
IMMICH_TEST_ASSET_TEMP_PATH,
|
||||||
|
createTestApp,
|
||||||
|
db,
|
||||||
|
itif,
|
||||||
|
restoreTempFolder,
|
||||||
|
runAllTests,
|
||||||
|
} from '@test/test-utils';
|
||||||
|
import { exiftool } from 'exiftool-vendored';
|
||||||
|
|
||||||
|
describe(`${AssetController.name} (e2e)`, () => {
|
||||||
|
let app: INestApplication;
|
||||||
|
let server: any;
|
||||||
|
let admin: LoginResponseDto;
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
app = await createTestApp(true);
|
||||||
|
server = app.getHttpServer();
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
await db.reset();
|
||||||
|
await restoreTempFolder();
|
||||||
|
await api.authApi.adminSignUp(server);
|
||||||
|
admin = await api.authApi.adminLogin(server);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(async () => {
|
||||||
|
await db.disconnect();
|
||||||
|
await app.close();
|
||||||
|
await restoreTempFolder();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe.only('should strip metadata of', () => {
|
||||||
|
let assetWithLocation: AssetResponseDto;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const fileContent = await fs.promises.readFile(
|
||||||
|
`${IMMICH_TEST_ASSET_PATH}/metadata/gps-position/thompson-springs.jpg`,
|
||||||
|
);
|
||||||
|
|
||||||
|
await api.assetApi.upload(server, admin.accessToken, 'test-asset-id', { content: fileContent });
|
||||||
|
|
||||||
|
const assets = await api.assetApi.getAllAssets(server, admin.accessToken);
|
||||||
|
|
||||||
|
expect(assets).toHaveLength(1);
|
||||||
|
assetWithLocation = assets[0];
|
||||||
|
|
||||||
|
expect(assetWithLocation).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
exifInfo: expect.objectContaining({ latitude: 39.115, longitude: -108.400968333333 }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
itif(runAllTests)('small webp thumbnails', async () => {
|
||||||
|
const assetId = assetWithLocation.id;
|
||||||
|
|
||||||
|
const thumbnail = await api.assetApi.getWebpThumbnail(server, admin.accessToken, assetId);
|
||||||
|
|
||||||
|
await fs.promises.writeFile(`${IMMICH_TEST_ASSET_TEMP_PATH}/thumbnail.webp`, thumbnail);
|
||||||
|
|
||||||
|
const exifData = await exiftool.read(`${IMMICH_TEST_ASSET_TEMP_PATH}/thumbnail.webp`);
|
||||||
|
|
||||||
|
expect(exifData).not.toHaveProperty('GPSLongitude');
|
||||||
|
expect(exifData).not.toHaveProperty('GPSLatitude');
|
||||||
|
});
|
||||||
|
|
||||||
|
itif(runAllTests)('large jpeg thumbnails', async () => {
|
||||||
|
const assetId = assetWithLocation.id;
|
||||||
|
|
||||||
|
const thumbnail = await api.assetApi.getJpegThumbnail(server, admin.accessToken, assetId);
|
||||||
|
|
||||||
|
await fs.promises.writeFile(`${IMMICH_TEST_ASSET_TEMP_PATH}/thumbnail.jpg`, thumbnail);
|
||||||
|
|
||||||
|
const exifData = await exiftool.read(`${IMMICH_TEST_ASSET_TEMP_PATH}/thumbnail.jpg`);
|
||||||
|
|
||||||
|
console.log(assetWithLocation);
|
||||||
|
|
||||||
|
expect(exifData).not.toHaveProperty('GPSLongitude');
|
||||||
|
expect(exifData).not.toHaveProperty('GPSLatitude');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -70,6 +70,8 @@ export async function createTestApp(runJobs = false, log = false): Promise<INest
|
||||||
|
|
||||||
export const runAllTests: boolean = process.env.IMMICH_RUN_ALL_TESTS === 'true';
|
export const runAllTests: boolean = process.env.IMMICH_RUN_ALL_TESTS === 'true';
|
||||||
|
|
||||||
|
export const itif = (condition: boolean) => (condition ? it : it.skip);
|
||||||
|
|
||||||
const directoryExists = async (dirPath: string) =>
|
const directoryExists = async (dirPath: string) =>
|
||||||
await fs.promises
|
await fs.promises
|
||||||
.access(dirPath)
|
.access(dirPath)
|
||||||
|
|
Loading…
Reference in a new issue