feat(server): separate quality for thumbnail and preview images (#13006)

* allow different thumbnail and preview quality, better config structure

* update web and api

* wording

* remove empty line?
This commit is contained in:
Mert 2024-09-28 02:01:04 -04:00 committed by GitHub
parent 4248594ac5
commit 995f0fda47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 369 additions and 198 deletions

View File

@ -416,6 +416,7 @@ Class | Method | HTTP request | Description
- [SystemConfigDto](doc//SystemConfigDto.md) - [SystemConfigDto](doc//SystemConfigDto.md)
- [SystemConfigFFmpegDto](doc//SystemConfigFFmpegDto.md) - [SystemConfigFFmpegDto](doc//SystemConfigFFmpegDto.md)
- [SystemConfigFacesDto](doc//SystemConfigFacesDto.md) - [SystemConfigFacesDto](doc//SystemConfigFacesDto.md)
- [SystemConfigGeneratedImageDto](doc//SystemConfigGeneratedImageDto.md)
- [SystemConfigImageDto](doc//SystemConfigImageDto.md) - [SystemConfigImageDto](doc//SystemConfigImageDto.md)
- [SystemConfigJobDto](doc//SystemConfigJobDto.md) - [SystemConfigJobDto](doc//SystemConfigJobDto.md)
- [SystemConfigLibraryDto](doc//SystemConfigLibraryDto.md) - [SystemConfigLibraryDto](doc//SystemConfigLibraryDto.md)

View File

@ -229,6 +229,7 @@ part 'model/stack_update_dto.dart';
part 'model/system_config_dto.dart'; part 'model/system_config_dto.dart';
part 'model/system_config_f_fmpeg_dto.dart'; part 'model/system_config_f_fmpeg_dto.dart';
part 'model/system_config_faces_dto.dart'; part 'model/system_config_faces_dto.dart';
part 'model/system_config_generated_image_dto.dart';
part 'model/system_config_image_dto.dart'; part 'model/system_config_image_dto.dart';
part 'model/system_config_job_dto.dart'; part 'model/system_config_job_dto.dart';
part 'model/system_config_library_dto.dart'; part 'model/system_config_library_dto.dart';

View File

@ -512,6 +512,8 @@ class ApiClient {
return SystemConfigFFmpegDto.fromJson(value); return SystemConfigFFmpegDto.fromJson(value);
case 'SystemConfigFacesDto': case 'SystemConfigFacesDto':
return SystemConfigFacesDto.fromJson(value); return SystemConfigFacesDto.fromJson(value);
case 'SystemConfigGeneratedImageDto':
return SystemConfigGeneratedImageDto.fromJson(value);
case 'SystemConfigImageDto': case 'SystemConfigImageDto':
return SystemConfigImageDto.fromJson(value); return SystemConfigImageDto.fromJson(value);
case 'SystemConfigJobDto': case 'SystemConfigJobDto':

View File

@ -0,0 +1,118 @@
//
// AUTO-GENERATED FILE, DO NOT MODIFY!
//
// @dart=2.18
// ignore_for_file: unused_element, unused_import
// ignore_for_file: always_put_required_named_parameters_first
// ignore_for_file: constant_identifier_names
// ignore_for_file: lines_longer_than_80_chars
part of openapi.api;
class SystemConfigGeneratedImageDto {
/// Returns a new [SystemConfigGeneratedImageDto] instance.
SystemConfigGeneratedImageDto({
required this.format,
required this.quality,
required this.size,
});
ImageFormat format;
/// Minimum value: 1
/// Maximum value: 100
int quality;
/// Minimum value: 1
int size;
@override
bool operator ==(Object other) => identical(this, other) || other is SystemConfigGeneratedImageDto &&
other.format == format &&
other.quality == quality &&
other.size == size;
@override
int get hashCode =>
// ignore: unnecessary_parenthesis
(format.hashCode) +
(quality.hashCode) +
(size.hashCode);
@override
String toString() => 'SystemConfigGeneratedImageDto[format=$format, quality=$quality, size=$size]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
json[r'format'] = this.format;
json[r'quality'] = this.quality;
json[r'size'] = this.size;
return json;
}
/// Returns a new [SystemConfigGeneratedImageDto] instance and imports its values from
/// [value] if it's a [Map], null otherwise.
// ignore: prefer_constructors_over_static_methods
static SystemConfigGeneratedImageDto? fromJson(dynamic value) {
upgradeDto(value, "SystemConfigGeneratedImageDto");
if (value is Map) {
final json = value.cast<String, dynamic>();
return SystemConfigGeneratedImageDto(
format: ImageFormat.fromJson(json[r'format'])!,
quality: mapValueOfType<int>(json, r'quality')!,
size: mapValueOfType<int>(json, r'size')!,
);
}
return null;
}
static List<SystemConfigGeneratedImageDto> listFromJson(dynamic json, {bool growable = false,}) {
final result = <SystemConfigGeneratedImageDto>[];
if (json is List && json.isNotEmpty) {
for (final row in json) {
final value = SystemConfigGeneratedImageDto.fromJson(row);
if (value != null) {
result.add(value);
}
}
}
return result.toList(growable: growable);
}
static Map<String, SystemConfigGeneratedImageDto> mapFromJson(dynamic json) {
final map = <String, SystemConfigGeneratedImageDto>{};
if (json is Map && json.isNotEmpty) {
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
for (final entry in json.entries) {
final value = SystemConfigGeneratedImageDto.fromJson(entry.value);
if (value != null) {
map[entry.key] = value;
}
}
}
return map;
}
// maps a json object with a list of SystemConfigGeneratedImageDto-objects as value to a dart map
static Map<String, List<SystemConfigGeneratedImageDto>> mapListFromJson(dynamic json, {bool growable = false,}) {
final map = <String, List<SystemConfigGeneratedImageDto>>{};
if (json is Map && json.isNotEmpty) {
// ignore: parameter_assignments
json = json.cast<String, dynamic>();
for (final entry in json.entries) {
map[entry.key] = SystemConfigGeneratedImageDto.listFromJson(entry.value, growable: growable,);
}
}
return map;
}
/// The list of required keys that must be present in a JSON.
static const requiredKeys = <String>{
'format',
'quality',
'size',
};
}

View File

@ -15,64 +15,42 @@ class SystemConfigImageDto {
SystemConfigImageDto({ SystemConfigImageDto({
required this.colorspace, required this.colorspace,
required this.extractEmbedded, required this.extractEmbedded,
required this.previewFormat, required this.preview,
required this.previewSize, required this.thumbnail,
required this.quality,
required this.thumbnailFormat,
required this.thumbnailSize,
}); });
Colorspace colorspace; Colorspace colorspace;
bool extractEmbedded; bool extractEmbedded;
ImageFormat previewFormat; SystemConfigGeneratedImageDto preview;
/// Minimum value: 1 SystemConfigGeneratedImageDto thumbnail;
int previewSize;
/// Minimum value: 1
/// Maximum value: 100
int quality;
ImageFormat thumbnailFormat;
/// Minimum value: 1
int thumbnailSize;
@override @override
bool operator ==(Object other) => identical(this, other) || other is SystemConfigImageDto && bool operator ==(Object other) => identical(this, other) || other is SystemConfigImageDto &&
other.colorspace == colorspace && other.colorspace == colorspace &&
other.extractEmbedded == extractEmbedded && other.extractEmbedded == extractEmbedded &&
other.previewFormat == previewFormat && other.preview == preview &&
other.previewSize == previewSize && other.thumbnail == thumbnail;
other.quality == quality &&
other.thumbnailFormat == thumbnailFormat &&
other.thumbnailSize == thumbnailSize;
@override @override
int get hashCode => int get hashCode =>
// ignore: unnecessary_parenthesis // ignore: unnecessary_parenthesis
(colorspace.hashCode) + (colorspace.hashCode) +
(extractEmbedded.hashCode) + (extractEmbedded.hashCode) +
(previewFormat.hashCode) + (preview.hashCode) +
(previewSize.hashCode) + (thumbnail.hashCode);
(quality.hashCode) +
(thumbnailFormat.hashCode) +
(thumbnailSize.hashCode);
@override @override
String toString() => 'SystemConfigImageDto[colorspace=$colorspace, extractEmbedded=$extractEmbedded, previewFormat=$previewFormat, previewSize=$previewSize, quality=$quality, thumbnailFormat=$thumbnailFormat, thumbnailSize=$thumbnailSize]'; String toString() => 'SystemConfigImageDto[colorspace=$colorspace, extractEmbedded=$extractEmbedded, preview=$preview, thumbnail=$thumbnail]';
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final json = <String, dynamic>{}; final json = <String, dynamic>{};
json[r'colorspace'] = this.colorspace; json[r'colorspace'] = this.colorspace;
json[r'extractEmbedded'] = this.extractEmbedded; json[r'extractEmbedded'] = this.extractEmbedded;
json[r'previewFormat'] = this.previewFormat; json[r'preview'] = this.preview;
json[r'previewSize'] = this.previewSize; json[r'thumbnail'] = this.thumbnail;
json[r'quality'] = this.quality;
json[r'thumbnailFormat'] = this.thumbnailFormat;
json[r'thumbnailSize'] = this.thumbnailSize;
return json; return json;
} }
@ -87,11 +65,8 @@ class SystemConfigImageDto {
return SystemConfigImageDto( return SystemConfigImageDto(
colorspace: Colorspace.fromJson(json[r'colorspace'])!, colorspace: Colorspace.fromJson(json[r'colorspace'])!,
extractEmbedded: mapValueOfType<bool>(json, r'extractEmbedded')!, extractEmbedded: mapValueOfType<bool>(json, r'extractEmbedded')!,
previewFormat: ImageFormat.fromJson(json[r'previewFormat'])!, preview: SystemConfigGeneratedImageDto.fromJson(json[r'preview'])!,
previewSize: mapValueOfType<int>(json, r'previewSize')!, thumbnail: SystemConfigGeneratedImageDto.fromJson(json[r'thumbnail'])!,
quality: mapValueOfType<int>(json, r'quality')!,
thumbnailFormat: ImageFormat.fromJson(json[r'thumbnailFormat'])!,
thumbnailSize: mapValueOfType<int>(json, r'thumbnailSize')!,
); );
} }
return null; return null;
@ -141,11 +116,8 @@ class SystemConfigImageDto {
static const requiredKeys = <String>{ static const requiredKeys = <String>{
'colorspace', 'colorspace',
'extractEmbedded', 'extractEmbedded',
'previewFormat', 'preview',
'previewSize', 'thumbnail',
'quality',
'thumbnailFormat',
'thumbnailSize',
}; };
} }

View File

@ -11654,6 +11654,28 @@
], ],
"type": "object" "type": "object"
}, },
"SystemConfigGeneratedImageDto": {
"properties": {
"format": {
"$ref": "#/components/schemas/ImageFormat"
},
"quality": {
"maximum": 100,
"minimum": 1,
"type": "integer"
},
"size": {
"minimum": 1,
"type": "integer"
}
},
"required": [
"format",
"quality",
"size"
],
"type": "object"
},
"SystemConfigImageDto": { "SystemConfigImageDto": {
"properties": { "properties": {
"colorspace": { "colorspace": {
@ -11662,34 +11684,18 @@
"extractEmbedded": { "extractEmbedded": {
"type": "boolean" "type": "boolean"
}, },
"previewFormat": { "preview": {
"$ref": "#/components/schemas/ImageFormat" "$ref": "#/components/schemas/SystemConfigGeneratedImageDto"
}, },
"previewSize": { "thumbnail": {
"minimum": 1, "$ref": "#/components/schemas/SystemConfigGeneratedImageDto"
"type": "integer"
},
"quality": {
"maximum": 100,
"minimum": 1,
"type": "integer"
},
"thumbnailFormat": {
"$ref": "#/components/schemas/ImageFormat"
},
"thumbnailSize": {
"minimum": 1,
"type": "integer"
} }
}, },
"required": [ "required": [
"colorspace", "colorspace",
"extractEmbedded", "extractEmbedded",
"previewFormat", "preview",
"previewSize", "thumbnail"
"quality",
"thumbnailFormat",
"thumbnailSize"
], ],
"type": "object" "type": "object"
}, },

View File

@ -1100,14 +1100,16 @@ export type SystemConfigFFmpegDto = {
transcode: TranscodePolicy; transcode: TranscodePolicy;
twoPass: boolean; twoPass: boolean;
}; };
export type SystemConfigGeneratedImageDto = {
format: ImageFormat;
quality: number;
size: number;
};
export type SystemConfigImageDto = { export type SystemConfigImageDto = {
colorspace: Colorspace; colorspace: Colorspace;
extractEmbedded: boolean; extractEmbedded: boolean;
previewFormat: ImageFormat; preview: SystemConfigGeneratedImageDto;
previewSize: number; thumbnail: SystemConfigGeneratedImageDto;
quality: number;
thumbnailFormat: ImageFormat;
thumbnailSize: number;
}; };
export type JobSettingsDto = { export type JobSettingsDto = {
concurrency: number; concurrency: number;

View File

@ -20,6 +20,7 @@ import {
VideoContainer, VideoContainer,
} from 'src/enum'; } from 'src/enum';
import { ConcurrentQueueName, QueueName } from 'src/interfaces/job.interface'; import { ConcurrentQueueName, QueueName } from 'src/interfaces/job.interface';
import { ImageOutputConfig } from 'src/interfaces/media.interface';
export interface SystemConfig { export interface SystemConfig {
ffmpeg: { ffmpeg: {
@ -109,11 +110,8 @@ export interface SystemConfig {
template: string; template: string;
}; };
image: { image: {
thumbnailFormat: ImageFormat; thumbnail: ImageOutputConfig;
thumbnailSize: number; preview: ImageOutputConfig;
previewFormat: ImageFormat;
previewSize: number;
quality: number;
colorspace: Colorspace; colorspace: Colorspace;
extractEmbedded: boolean; extractEmbedded: boolean;
}; };
@ -259,11 +257,16 @@ export const defaults = Object.freeze<SystemConfig>({
template: '{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}', template: '{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}',
}, },
image: { image: {
thumbnailFormat: ImageFormat.WEBP, thumbnail: {
thumbnailSize: 250, format: ImageFormat.WEBP,
previewFormat: ImageFormat.JPEG, size: 250,
previewSize: 1440,
quality: 80, quality: 80,
},
preview: {
format: ImageFormat.JPEG,
size: 1440,
quality: 80,
},
colorspace: Colorspace.P3, colorspace: Colorspace.P3,
extractEmbedded: false, extractEmbedded: false,
}, },

View File

@ -473,26 +473,10 @@ export class SystemConfigThemeDto {
customCss!: string; customCss!: string;
} }
class SystemConfigImageDto { class SystemConfigGeneratedImageDto {
@IsEnum(ImageFormat) @IsEnum(ImageFormat)
@ApiProperty({ enumName: 'ImageFormat', enum: ImageFormat }) @ApiProperty({ enumName: 'ImageFormat', enum: ImageFormat })
thumbnailFormat!: ImageFormat; format!: ImageFormat;
@IsInt()
@Min(1)
@Type(() => Number)
@ApiProperty({ type: 'integer' })
thumbnailSize!: number;
@IsEnum(ImageFormat)
@ApiProperty({ enumName: 'ImageFormat', enum: ImageFormat })
previewFormat!: ImageFormat;
@IsInt()
@Min(1)
@Type(() => Number)
@ApiProperty({ type: 'integer' })
previewSize!: number;
@IsInt() @IsInt()
@Min(1) @Min(1)
@ -501,6 +485,24 @@ class SystemConfigImageDto {
@ApiProperty({ type: 'integer' }) @ApiProperty({ type: 'integer' })
quality!: number; quality!: number;
@IsInt()
@Min(1)
@Type(() => Number)
@ApiProperty({ type: 'integer' })
size!: number;
}
class SystemConfigImageDto {
@Type(() => SystemConfigGeneratedImageDto)
@ValidateNested()
@IsObject()
thumbnail!: SystemConfigGeneratedImageDto;
@Type(() => SystemConfigGeneratedImageDto)
@ValidateNested()
@IsObject()
preview!: SystemConfigGeneratedImageDto;
@IsEnum(Colorspace) @IsEnum(Colorspace)
@ApiProperty({ enumName: 'Colorspace', enum: Colorspace }) @ApiProperty({ enumName: 'Colorspace', enum: Colorspace })
colorspace!: Colorspace; colorspace!: Colorspace;

View File

@ -10,11 +10,14 @@ export interface CropOptions {
height: number; height: number;
} }
export interface ThumbnailOptions { export interface ImageOutputConfig {
size: number;
format: ImageFormat; format: ImageFormat;
colorspace: string;
quality: number; quality: number;
size: number;
}
export interface ThumbnailOptions extends ImageOutputConfig {
colorspace: string;
crop?: CropOptions; crop?: CropOptions;
processInvalidImages: boolean; processInvalidImages: boolean;
} }

View File

@ -0,0 +1,37 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class SeparateQualityForThumbnailAndPreview1727471863507 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
update system_metadata
set value = jsonb_set(value, '{image}', jsonb_strip_nulls(
jsonb_build_object(
'preview', jsonb_build_object(
'format', value->'image'->'previewFormat',
'quality', value->'image'->'quality',
'size', value->'image'->'previewSize'),
'thumbnail', jsonb_build_object(
'format', value->'image'->'thumbnailFormat',
'quality', value->'image'->'quality',
'size', value->'image'->'thumbnailSize'),
'extractEmbedded', value->'extractEmbedded',
'colorspace', value->'colorspace'
)))
where key = 'system-config'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
update system_metadata
set value = jsonb_set(value, '{image}', jsonb_strip_nulls(jsonb_build_object(
'previewFormat', value->'image'->'preview'->'format',
'previewSize', value->'image'->'preview'->'size',
'thumbnailFormat', value->'image'->'thumbnail'->'format',
'thumbnailSize', value->'image'->'thumbnail'->'size',
'extractEmbedded', value->'extractEmbedded',
'colorspace', value->'colorspace',
'quality', value->'image'->'preview'->'quality'
)))
where key = 'system-config'`);
}
}

View File

@ -285,7 +285,7 @@ describe(MediaService.name, () => {
}); });
it.each(Object.values(ImageFormat))('should generate a %s preview for an image when specified', async (format) => { it.each(Object.values(ImageFormat))('should generate a %s preview for an image when specified', async (format) => {
systemMock.get.mockResolvedValue({ image: { previewFormat: format } }); systemMock.get.mockResolvedValue({ image: { preview: { format } } });
assetMock.getByIds.mockResolvedValue([assetStub.image]); assetMock.getByIds.mockResolvedValue([assetStub.image]);
const previewPath = `upload/thumbs/user-id/as/se/asset-id-preview.${format}`; const previewPath = `upload/thumbs/user-id/as/se/asset-id-preview.${format}`;
@ -307,7 +307,7 @@ describe(MediaService.name, () => {
}); });
it('should delete previous preview if different path', async () => { it('should delete previous preview if different path', async () => {
systemMock.get.mockResolvedValue({ image: { thumbnailFormat: ImageFormat.WEBP } }); systemMock.get.mockResolvedValue({ image: { thumbnail: { format: ImageFormat.WEBP } } });
assetMock.getByIds.mockResolvedValue([assetStub.image]); assetMock.getByIds.mockResolvedValue([assetStub.image]);
await sut.handleGeneratePreview({ id: assetStub.image.id }); await sut.handleGeneratePreview({ id: assetStub.image.id });
@ -464,7 +464,7 @@ describe(MediaService.name, () => {
it.each(Object.values(ImageFormat))( it.each(Object.values(ImageFormat))(
'should generate a %s thumbnail for an image when specified', 'should generate a %s thumbnail for an image when specified',
async (format) => { async (format) => {
systemMock.get.mockResolvedValue({ image: { thumbnailFormat: format } }); systemMock.get.mockResolvedValue({ image: { thumbnail: { format } } });
assetMock.getByIds.mockResolvedValue([assetStub.image]); assetMock.getByIds.mockResolvedValue([assetStub.image]);
const thumbnailPath = `upload/thumbs/user-id/as/se/asset-id-thumbnail.${format}`; const thumbnailPath = `upload/thumbs/user-id/as/se/asset-id-thumbnail.${format}`;
@ -487,7 +487,7 @@ describe(MediaService.name, () => {
); );
it('should delete previous thumbnail if different path', async () => { it('should delete previous thumbnail if different path', async () => {
systemMock.get.mockResolvedValue({ image: { thumbnailFormat: ImageFormat.WEBP } }); systemMock.get.mockResolvedValue({ image: { thumbnail: { format: ImageFormat.WEBP } } });
assetMock.getByIds.mockResolvedValue([assetStub.image]); assetMock.getByIds.mockResolvedValue([assetStub.image]);
await sut.handleGenerateThumbnail({ id: assetStub.image.id }); await sut.handleGenerateThumbnail({ id: assetStub.image.id });

View File

@ -10,7 +10,6 @@ import {
AssetType, AssetType,
AudioCodec, AudioCodec,
Colorspace, Colorspace,
ImageFormat,
LogLevel, LogLevel,
StorageFolder, StorageFolder,
TranscodeHWAccel, TranscodeHWAccel,
@ -175,18 +174,15 @@ export class MediaService {
return JobStatus.FAILED; return JobStatus.FAILED;
} }
await this.storageCore.moveAssetImage(asset, AssetPathType.PREVIEW, image.previewFormat); await this.storageCore.moveAssetImage(asset, AssetPathType.PREVIEW, image.preview.format);
await this.storageCore.moveAssetImage(asset, AssetPathType.THUMBNAIL, image.thumbnailFormat); await this.storageCore.moveAssetImage(asset, AssetPathType.THUMBNAIL, image.thumbnail.format);
await this.storageCore.moveAssetVideo(asset); await this.storageCore.moveAssetVideo(asset);
return JobStatus.SUCCESS; return JobStatus.SUCCESS;
} }
async handleGeneratePreview({ id }: IEntityJob): Promise<JobStatus> { async handleGeneratePreview({ id }: IEntityJob): Promise<JobStatus> {
const [{ image }, [asset]] = await Promise.all([ const [asset] = await this.assetRepository.getByIds([id], { exifInfo: true, files: true });
this.configCore.getConfig({ withCache: true }),
this.assetRepository.getByIds([id], { exifInfo: true, files: true }),
]);
if (!asset) { if (!asset) {
return JobStatus.FAILED; return JobStatus.FAILED;
} }
@ -195,7 +191,7 @@ export class MediaService {
return JobStatus.SKIPPED; return JobStatus.SKIPPED;
} }
const previewPath = await this.generateThumbnail(asset, AssetPathType.PREVIEW, image.previewFormat); const previewPath = await this.generateThumbnail(asset, AssetPathType.PREVIEW);
if (!previewPath) { if (!previewPath) {
return JobStatus.SKIPPED; return JobStatus.SKIPPED;
} }
@ -213,9 +209,9 @@ export class MediaService {
return JobStatus.SUCCESS; return JobStatus.SUCCESS;
} }
private async generateThumbnail(asset: AssetEntity, type: GeneratedImageType, format: ImageFormat) { private async generateThumbnail(asset: AssetEntity, type: GeneratedImageType) {
const { image, ffmpeg } = await this.configCore.getConfig({ withCache: true }); const { image, ffmpeg } = await this.configCore.getConfig({ withCache: true });
const size = type === AssetPathType.PREVIEW ? image.previewSize : image.thumbnailSize; const { size, format, quality } = image[type];
const path = StorageCore.getImagePath(asset, type, format); const path = StorageCore.getImagePath(asset, type, format);
this.storageCore.ensureFolders(path); this.storageCore.ensureFolders(path);
@ -226,13 +222,13 @@ export class MediaService {
const didExtract = shouldExtract && (await this.mediaRepository.extract(asset.originalPath, extractedPath)); const didExtract = shouldExtract && (await this.mediaRepository.extract(asset.originalPath, extractedPath));
try { try {
const useExtracted = didExtract && (await this.shouldUseExtractedImage(extractedPath, image.previewSize)); const useExtracted = didExtract && (await this.shouldUseExtractedImage(extractedPath, image.preview.size));
const colorspace = this.isSRGB(asset) ? Colorspace.SRGB : image.colorspace; const colorspace = this.isSRGB(asset) ? Colorspace.SRGB : image.colorspace;
const imageOptions = { const imageOptions = {
format, format,
size, size,
colorspace, colorspace,
quality: image.quality, quality,
processInvalidImages: process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true', processInvalidImages: process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true',
}; };
@ -274,10 +270,7 @@ export class MediaService {
} }
async handleGenerateThumbnail({ id }: IEntityJob): Promise<JobStatus> { async handleGenerateThumbnail({ id }: IEntityJob): Promise<JobStatus> {
const [{ image }, [asset]] = await Promise.all([ const [asset] = await this.assetRepository.getByIds([id], { exifInfo: true, files: true });
this.configCore.getConfig({ withCache: true }),
this.assetRepository.getByIds([id], { exifInfo: true, files: true }),
]);
if (!asset) { if (!asset) {
return JobStatus.FAILED; return JobStatus.FAILED;
} }
@ -286,7 +279,7 @@ export class MediaService {
return JobStatus.SKIPPED; return JobStatus.SKIPPED;
} }
const thumbnailPath = await this.generateThumbnail(asset, AssetPathType.THUMBNAIL, image.thumbnailFormat); const thumbnailPath = await this.generateThumbnail(asset, AssetPathType.THUMBNAIL);
if (!thumbnailPath) { if (!thumbnailPath) {
return JobStatus.SKIPPED; return JobStatus.SKIPPED;
} }

View File

@ -574,7 +574,7 @@ export class PersonService {
format: ImageFormat.JPEG, format: ImageFormat.JPEG,
size: FACE_THUMBNAIL_SIZE, size: FACE_THUMBNAIL_SIZE,
colorspace: image.colorspace, colorspace: image.colorspace,
quality: image.quality, quality: image.thumbnail.quality,
crop: this.getCrop({ old: { width: oldWidth, height: oldHeight }, new: { width, height } }, { x1, y1, x2, y2 }), crop: this.getCrop({ old: { width: oldWidth, height: oldHeight }, new: { width, height } }, { x1, y1, x2, y2 }),
processInvalidImages: process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true', processInvalidImages: process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true',
} as const; } as const;

View File

@ -135,11 +135,16 @@ const updatedConfig = Object.freeze<SystemConfig>({
template: '{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}', template: '{{y}}/{{y}}-{{MM}}-{{dd}}/{{filename}}',
}, },
image: { image: {
thumbnailFormat: ImageFormat.WEBP, thumbnail: {
thumbnailSize: 250, size: 250,
previewFormat: ImageFormat.JPEG, format: ImageFormat.WEBP,
previewSize: 1440,
quality: 80, quality: 80,
},
preview: {
size: 1440,
format: ImageFormat.JPEG,
quality: 80,
},
colorspace: Colorspace.P3, colorspace: Colorspace.P3,
extractEmbedded: false, extractEmbedded: false,
}, },

View File

@ -11,6 +11,7 @@
SettingInputFieldType, SettingInputFieldType,
} from '$lib/components/shared-components/settings/setting-input-field.svelte'; } from '$lib/components/shared-components/settings/setting-input-field.svelte';
import { t } from 'svelte-i18n'; import { t } from 'svelte-i18n';
import SettingAccordion from '$lib/components/shared-components/settings/setting-accordion.svelte';
export let savedConfig: SystemConfigDto; export let savedConfig: SystemConfigDto;
export let defaultConfig: SystemConfigDto; export let defaultConfig: SystemConfigDto;
@ -24,24 +25,30 @@
<div in:fade={{ duration: 500 }}> <div in:fade={{ duration: 500 }}>
<form autocomplete="off" on:submit|preventDefault> <form autocomplete="off" on:submit|preventDefault>
<div class="ml-4 mt-4 flex flex-col gap-4"> <div class="ml-4 mt-4 flex flex-col gap-4">
<SettingAccordion
key="thumbnail-settings"
title={$t('admin.image_thumbnail_title')}
subtitle={$t('admin.image_thumbnail_description')}
isOpen={true}
>
<SettingSelect <SettingSelect
label={$t('admin.image_thumbnail_format')} label={$t('admin.image_format')}
desc={$t('admin.image_format_description')} desc={$t('admin.image_format_description')}
bind:value={config.image.thumbnailFormat} bind:value={config.image.thumbnail.format}
options={[ options={[
{ value: ImageFormat.Jpeg, text: 'JPEG' }, { value: ImageFormat.Jpeg, text: 'JPEG' },
{ value: ImageFormat.Webp, text: 'WebP' }, { value: ImageFormat.Webp, text: 'WebP' },
]} ]}
name="format" name="format"
isEdited={config.image.thumbnailFormat !== savedConfig.image.thumbnailFormat} isEdited={config.image.thumbnail.format !== savedConfig.image.thumbnail.format}
{disabled} {disabled}
/> />
<SettingSelect <SettingSelect
label={$t('admin.image_thumbnail_resolution')} label={$t('admin.image_resolution')}
desc={$t('admin.image_thumbnail_resolution_description')} desc={$t('admin.image_resolution_description')}
number number
bind:value={config.image.thumbnailSize} bind:value={config.image.thumbnail.size}
options={[ options={[
{ value: 1080, text: '1080p' }, { value: 1080, text: '1080p' },
{ value: 720, text: '720p' }, { value: 720, text: '720p' },
@ -50,28 +57,44 @@
{ value: 200, text: '200p' }, { value: 200, text: '200p' },
]} ]}
name="resolution" name="resolution"
isEdited={config.image.thumbnailSize !== savedConfig.image.thumbnailSize} isEdited={config.image.thumbnail.size !== savedConfig.image.thumbnail.size}
{disabled} {disabled}
/> />
<SettingInputField
inputType={SettingInputFieldType.NUMBER}
label={$t('admin.image_quality')}
desc={$t('admin.image_thumbnail_quality_description')}
bind:value={config.image.thumbnail.quality}
isEdited={config.image.thumbnail.quality !== savedConfig.image.thumbnail.quality}
{disabled}
/>
</SettingAccordion>
<SettingAccordion
key="preview-settings"
title={$t('admin.image_preview_title')}
subtitle={$t('admin.image_preview_description')}
isOpen={true}
>
<SettingSelect <SettingSelect
label={$t('admin.image_preview_format')} label={$t('admin.image_format')}
desc={$t('admin.image_format_description')} desc={$t('admin.image_format_description')}
bind:value={config.image.previewFormat} bind:value={config.image.preview.format}
options={[ options={[
{ value: ImageFormat.Jpeg, text: 'JPEG' }, { value: ImageFormat.Jpeg, text: 'JPEG' },
{ value: ImageFormat.Webp, text: 'WebP' }, { value: ImageFormat.Webp, text: 'WebP' },
]} ]}
name="format" name="format"
isEdited={config.image.previewFormat !== savedConfig.image.previewFormat} isEdited={config.image.preview.format !== savedConfig.image.preview.format}
{disabled} {disabled}
/> />
<SettingSelect <SettingSelect
label={$t('admin.image_preview_resolution')} label={$t('admin.image_resolution')}
desc={$t('admin.image_preview_resolution_description')} desc={$t('admin.image_resolution_description')}
number number
bind:value={config.image.previewSize} bind:value={config.image.preview.size}
options={[ options={[
{ value: 2160, text: '4K' }, { value: 2160, text: '4K' },
{ value: 1440, text: '1440p' }, { value: 1440, text: '1440p' },
@ -79,18 +102,19 @@
{ value: 720, text: '720p' }, { value: 720, text: '720p' },
]} ]}
name="resolution" name="resolution"
isEdited={config.image.previewSize !== savedConfig.image.previewSize} isEdited={config.image.preview.size !== savedConfig.image.preview.size}
{disabled} {disabled}
/> />
<SettingInputField <SettingInputField
inputType={SettingInputFieldType.NUMBER} inputType={SettingInputFieldType.NUMBER}
label={$t('admin.image_quality')} label={$t('admin.image_quality')}
desc={$t('admin.image_quality_description')} desc={$t('admin.image_preview_quality_description')}
bind:value={config.image.quality} bind:value={config.image.preview.quality}
isEdited={config.image.quality !== savedConfig.image.quality} isEdited={config.image.preview.quality !== savedConfig.image.preview.quality}
{disabled} {disabled}
/> />
</SettingAccordion>
<SettingSwitch <SettingSwitch
title={$t('admin.image_prefer_wide_gamut')} title={$t('admin.image_prefer_wide_gamut')}

View File

@ -54,21 +54,23 @@
"failed_job_command": "Command {command} failed for job: {job}", "failed_job_command": "Command {command} failed for job: {job}",
"force_delete_user_warning": "WARNING: This will immediately remove the user and all assets. This cannot be undone and the files cannot be recovered.", "force_delete_user_warning": "WARNING: This will immediately remove the user and all assets. This cannot be undone and the files cannot be recovered.",
"forcing_refresh_library_files": "Forcing refresh of all library files", "forcing_refresh_library_files": "Forcing refresh of all library files",
"image_format": "Format",
"image_format_description": "WebP produces smaller files than JPEG, but is slower to encode.", "image_format_description": "WebP produces smaller files than JPEG, but is slower to encode.",
"image_prefer_embedded_preview": "Prefer embedded preview", "image_prefer_embedded_preview": "Prefer embedded preview",
"image_prefer_embedded_preview_setting_description": "Use embedded previews in RAW photos as the input to image processing when available. This can produce more accurate colors for some images, but the quality of the preview is camera-dependent and the image may have more compression artifacts.", "image_prefer_embedded_preview_setting_description": "Use embedded previews in RAW photos as the input to image processing when available. This can produce more accurate colors for some images, but the quality of the preview is camera-dependent and the image may have more compression artifacts.",
"image_prefer_wide_gamut": "Prefer wide gamut", "image_prefer_wide_gamut": "Prefer wide gamut",
"image_prefer_wide_gamut_setting_description": "Use Display P3 for thumbnails. This better preserves the vibrance of images with wide colorspaces, but images may appear differently on old devices with an old browser version. sRGB images are kept as sRGB to avoid color shifts.", "image_prefer_wide_gamut_setting_description": "Use Display P3 for thumbnails. This better preserves the vibrance of images with wide colorspaces, but images may appear differently on old devices with an old browser version. sRGB images are kept as sRGB to avoid color shifts.",
"image_preview_format": "Preview format", "image_preview_description": "Medium-size image with stripped metadata, used when viewing a single asset and for machine learning",
"image_preview_resolution": "Preview resolution", "image_preview_quality_description": "Preview quality from 1-100. Higher is better, but produces larger files and can reduce app responsiveness. Setting a low value may affect machine learning quality.",
"image_preview_resolution_description": "Used when viewing a single photo and for machine learning. Higher resolutions can preserve more detail but take longer to encode, have larger file sizes, and can reduce app responsiveness.", "image_preview_title": "Preview Settings",
"image_quality": "Quality", "image_quality": "Quality",
"image_quality_description": "Image quality from 1-100. Higher is better for quality but produces larger files, this option affects the Preview and Thumbnail images.", "image_resolution": "Resolution",
"image_resolution_description": "Higher resolutions can preserve more detail but take longer to encode, have larger file sizes and can reduce app responsiveness.",
"image_settings": "Image Settings", "image_settings": "Image Settings",
"image_settings_description": "Manage the quality and resolution of generated images", "image_settings_description": "Manage the quality and resolution of generated images",
"image_thumbnail_format": "Thumbnail format", "image_thumbnail_description": "Small thumbnail with stripped metadata, used when viewing groups of photos like the main timeline",
"image_thumbnail_resolution": "Thumbnail resolution", "image_thumbnail_quality_description": "Thumbnail quality from 1-100. Higher is better, but produces larger files and can reduce app responsiveness.",
"image_thumbnail_resolution_description": "Used when viewing groups of photos (main timeline, album view, etc.). Higher resolutions can preserve more detail but take longer to encode, have larger file sizes, and can reduce app responsiveness.", "image_thumbnail_title": "Thumbnail Settings",
"job_concurrency": "{job} concurrency", "job_concurrency": "{job} concurrency",
"job_created": "Job created", "job_created": "Job created",
"job_not_concurrency_safe": "This job is not concurrency-safe.", "job_not_concurrency_safe": "This job is not concurrency-safe.",