mirror of
https://github.com/immich-app/immich.git
synced 2026-03-23 04:49:10 +03:00
feat: warn when losing transparency during thumbnail generation (#26243)
* feat: preserve alpha * refactor: use isTransparent naming and separate getImageMetadata * warn instead of preserve
This commit is contained in:
@@ -153,6 +153,33 @@ describe('mimeTypes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
describe('canBeTransparent', () => {
|
||||
for (const img of [
|
||||
'a.avif',
|
||||
'a.bmp',
|
||||
'a.gif',
|
||||
'a.heic',
|
||||
'a.heif',
|
||||
'a.hif',
|
||||
'a.jxl',
|
||||
'a.png',
|
||||
'a.svg',
|
||||
'a.tif',
|
||||
'a.tiff',
|
||||
'a.webp',
|
||||
]) {
|
||||
it(`should return true for ${img}`, () => {
|
||||
expect(mimeTypes.canBeTransparent(img)).toBe(true);
|
||||
});
|
||||
}
|
||||
|
||||
for (const img of ['a.jpg', 'a.jpeg', 'a.jpe', 'a.insp', 'a.jp2', 'a.cr3', 'a.dng', 'a.nef', 'a.arw']) {
|
||||
it(`should return false for ${img}`, () => {
|
||||
expect(mimeTypes.canBeTransparent(img)).toBe(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe('animated image', () => {
|
||||
for (const img of ['a.avif', 'a.gif', 'a.webp']) {
|
||||
it('should identify animated image mime types as such', () => {
|
||||
|
||||
@@ -77,6 +77,21 @@ const extensionOverrides: Record<string, string> = {
|
||||
'image/jpeg': '.jpg',
|
||||
};
|
||||
|
||||
const transparentCapableExtensions = new Set([
|
||||
'.avif',
|
||||
'.bmp',
|
||||
'.gif',
|
||||
'.heic',
|
||||
'.heif',
|
||||
'.hif',
|
||||
'.jxl',
|
||||
'.png',
|
||||
'.svg',
|
||||
'.tif',
|
||||
'.tiff',
|
||||
'.webp',
|
||||
]);
|
||||
|
||||
const profileExtensions = new Set(['.avif', '.dng', '.heic', '.heif', '.jpeg', '.jpg', '.png', '.webp', '.svg']);
|
||||
const profile: Record<string, string[]> = Object.fromEntries(
|
||||
Object.entries(image).filter(([key]) => profileExtensions.has(key)),
|
||||
@@ -134,6 +149,7 @@ export const mimeTypes = {
|
||||
isProfile: (filename: string) => isType(filename, profile),
|
||||
isSidecar: (filename: string) => isType(filename, sidecar),
|
||||
isVideo: (filename: string) => isType(filename, video),
|
||||
canBeTransparent: (filename: string) => transparentCapableExtensions.has(extname(filename).toLowerCase()),
|
||||
isRaw: (filename: string) => isType(filename, raw),
|
||||
lookup,
|
||||
/** return an extension (including a leading `.`) for a mime-type */
|
||||
|
||||
Reference in New Issue
Block a user