Skip to content

Commit

Permalink
Update server/src/services/metadata.service.ts
Browse files Browse the repository at this point in the history
Co-authored-by: Mert <[email protected]>
  • Loading branch information
C-Otto and mertalev committed Oct 15, 2024
1 parent 49e86a3 commit 7722769
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,25 +336,16 @@ export class MetadataService extends BaseService {
return JobStatus.SUCCESS;
}

private getImageDimensions(exifTags: ImmichTags): { width: number; height: number } {
private getImageDimensions(exifTags: ImmichTags): { width?: number; height?: number } {
/*
* The "true" values for width and height are a bit hidden, depending on the camera model and file format.
* For RAW images in the CR2 or RAF format, the "ImageSize" value seems to be correct,
* but ImageWidth and ImageHeight are not correct (they contain the dimensions of the preview image).
*/

let width = Number.NaN;
let height = Number.NaN;
const imageSize = exifTags.ImageSize;
if (imageSize && imageSize.indexOf('x') > 0) {
// ImageSize is "width x height" (e.g. "100x200")
const split = imageSize.split('x');
width = Number.parseInt(split[0]);
height = Number.parseInt(split[1]);
}
let [width, height] = exifTags.ImageSize?.split('x').map((dim) => Number.parseInt(dim) || undefined) || [];
if (!width || !height) {
width = exifTags.ImageWidth ?? Number.NaN;
height = exifTags.ImageHeight ?? Number.NaN;
[width, height] = [exifTags.ImageWidth, exifTags.ImageHeight];
}
return { width, height };
}
Expand Down

0 comments on commit 7722769

Please sign in to comment.