Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): correct rotation for common files #14092

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/src/interfaces/media.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface DecodeImageOptions {
export interface DecodeToBufferOptions extends DecodeImageOptions {
size: number;
orientation?: ExifOrientation;
isEmbeddedImage?: boolean;
mertalev marked this conversation as resolved.
Show resolved Hide resolved
}

export type GenerateThumbnailOptions = ImageOptions & DecodeImageOptions;
Expand Down
18 changes: 11 additions & 7 deletions server/src/repositories/media.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,18 @@ export class MediaRepository implements IMediaRepository {
.withIccProfile(options.colorspace);

if (!options.raw) {
const { angle, flip, flop } = options.orientation ? ORIENTATION_TO_SHARP_ROTATION[options.orientation] : {};
pipeline = pipeline.rotate(angle);
if (flip) {
pipeline = pipeline.flip();
}
if (options.isEmbeddedImage) {
const { angle, flip, flop } = options.orientation ? ORIENTATION_TO_SHARP_ROTATION[options.orientation] : {};
pipeline = pipeline.rotate(angle);
if (flip) {
pipeline = pipeline.flip();
}

if (flop) {
pipeline = pipeline.flop();
if (flop) {
pipeline = pipeline.flop();
}
} else {
pipeline = pipeline.rotate();
}
}

Expand Down
9 changes: 8 additions & 1 deletion server/src/services/media.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,14 @@ export class MediaService extends BaseService {
const processInvalidImages = process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true';

const orientation = Number(asset.exifInfo?.orientation) || undefined;
const decodeOptions = { colorspace, processInvalidImages, size: image.preview.size, orientation };
const decodeOptions = {
colorspace,
processInvalidImages,
size: image.preview.size,
orientation,
isEmbeddedImage: didExtract,
};

const { data, info } = await this.mediaRepository.decodeImage(inputPath, decodeOptions);

const options = { colorspace, processInvalidImages, raw: info };
Expand Down
Loading