mirror of
https://github.com/KevinMidboe/immich.git
synced 2026-01-26 02:55:49 +00:00
feat(server): enhanced thumbnails generation code (#2147)
* Add size parameter to extractVideoThumbnail * Ensure minimum dimension of webp thumbnail
This commit is contained in:
@@ -7,6 +7,6 @@ export interface ResizeOptions {
|
||||
|
||||
export interface IMediaRepository {
|
||||
resize(input: string, output: string, options: ResizeOptions): Promise<void>;
|
||||
extractVideoThumbnail(input: string, output: string): Promise<void>;
|
||||
extractVideoThumbnail(input: string, output: string, size: number): Promise<void>;
|
||||
extractThumbnailFromExif(input: string, output: string): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -114,6 +114,7 @@ describe(MediaService.name, () => {
|
||||
expect(mediaMock.extractVideoThumbnail).toHaveBeenCalledWith(
|
||||
'/original/path.ext',
|
||||
'upload/thumbs/user-id/asset-id.jpeg',
|
||||
1440,
|
||||
);
|
||||
expect(assetMock.save).toHaveBeenCalledWith({
|
||||
id: 'asset-id',
|
||||
|
||||
@@ -44,9 +44,13 @@ export class MediaService {
|
||||
this.storageRepository.mkdirSync(resizePath);
|
||||
const jpegThumbnailPath = join(resizePath, `${asset.id}.jpeg`);
|
||||
|
||||
const thumbnailDimension = 1440;
|
||||
if (asset.type == AssetType.IMAGE) {
|
||||
try {
|
||||
await this.mediaRepository.resize(asset.originalPath, jpegThumbnailPath, { size: 1440, format: 'jpeg' });
|
||||
await this.mediaRepository.resize(asset.originalPath, jpegThumbnailPath, {
|
||||
size: thumbnailDimension,
|
||||
format: 'jpeg',
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`Failed to generate jpeg thumbnail using sharp, trying with exiftool-vendored (asset=${asset.id})`,
|
||||
@@ -57,7 +61,7 @@ export class MediaService {
|
||||
|
||||
if (asset.type == AssetType.VIDEO) {
|
||||
this.logger.log('Start Generating Video Thumbnail');
|
||||
await this.mediaRepository.extractVideoThumbnail(asset.originalPath, jpegThumbnailPath);
|
||||
await this.mediaRepository.extractVideoThumbnail(asset.originalPath, jpegThumbnailPath, thumbnailDimension);
|
||||
this.logger.log(`Generating Video Thumbnail Success ${asset.id}`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user