2018-05-13 00:19:51 +08:00
|
|
|
import {DirectoryDTO} from './DirectoryDTO';
|
2018-11-02 17:40:09 +08:00
|
|
|
import {ImageSize} from './PhotoDTO';
|
|
|
|
import {OrientationTypes} from 'ts-exif-parser';
|
2016-12-28 03:55:51 +08:00
|
|
|
|
|
|
|
export interface PhotoDTO {
|
2017-06-11 04:32:56 +08:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
directory: DirectoryDTO;
|
|
|
|
metadata: PhotoMetadata;
|
|
|
|
readyThumbnails: Array<number>;
|
|
|
|
readyIcon: boolean;
|
2016-12-28 03:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface PhotoMetadata {
|
2017-06-11 04:32:56 +08:00
|
|
|
keywords: Array<string>;
|
|
|
|
cameraData: CameraMetadata;
|
|
|
|
positionData: PositionMetaData;
|
2018-11-02 17:40:09 +08:00
|
|
|
orientation: OrientationTypes;
|
2017-06-11 04:32:56 +08:00
|
|
|
size: ImageSize;
|
|
|
|
creationDate: number;
|
2017-07-10 04:00:42 +08:00
|
|
|
fileSize: number;
|
2016-12-28 03:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ImageSize {
|
2017-06-11 04:32:56 +08:00
|
|
|
width: number;
|
|
|
|
height: number;
|
2016-12-28 03:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CameraMetadata {
|
2017-06-11 04:32:56 +08:00
|
|
|
ISO?: number;
|
|
|
|
model?: string;
|
2017-07-11 04:00:22 +08:00
|
|
|
make?: string;
|
2017-06-11 04:32:56 +08:00
|
|
|
fStop?: number;
|
|
|
|
exposure?: number;
|
|
|
|
focalLength?: number;
|
|
|
|
lens?: string;
|
2016-12-28 03:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface PositionMetaData {
|
2017-06-11 04:32:56 +08:00
|
|
|
GPSData?: GPSMetadata;
|
|
|
|
country?: string;
|
|
|
|
state?: string;
|
|
|
|
city?: string;
|
2016-12-28 03:55:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface GPSMetadata {
|
2017-06-11 04:32:56 +08:00
|
|
|
latitude?: number;
|
|
|
|
longitude?: number;
|
2017-07-19 05:27:14 +08:00
|
|
|
altitude?: number;
|
2018-05-14 04:59:57 +08:00
|
|
|
}
|
2016-12-28 03:55:51 +08:00
|
|
|
|
2018-05-14 04:59:57 +08:00
|
|
|
export module PhotoDTO {
|
|
|
|
export const hasPositionData = (photo: PhotoDTO): boolean => {
|
|
|
|
return !!photo.metadata.positionData &&
|
|
|
|
!!(photo.metadata.positionData.city ||
|
|
|
|
photo.metadata.positionData.state ||
|
|
|
|
photo.metadata.positionData.country ||
|
|
|
|
(photo.metadata.positionData.GPSData &&
|
|
|
|
photo.metadata.positionData.GPSData.altitude &&
|
|
|
|
photo.metadata.positionData.GPSData.latitude &&
|
|
|
|
photo.metadata.positionData.GPSData.longitude));
|
|
|
|
};
|
2018-11-02 17:40:09 +08:00
|
|
|
|
|
|
|
export const isSideWay = (photo: PhotoDTO): boolean => {
|
|
|
|
return photo.metadata.orientation === OrientationTypes.LEFT_TOP ||
|
|
|
|
photo.metadata.orientation === OrientationTypes.RIGHT_TOP ||
|
|
|
|
photo.metadata.orientation === OrientationTypes.LEFT_BOTTOM ||
|
|
|
|
photo.metadata.orientation === OrientationTypes.RIGHT_BOTTOM;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getRotatedSize = (photo: PhotoDTO): ImageSize => {
|
|
|
|
if (isSideWay(photo)) {
|
|
|
|
// noinspection JSSuspiciousNameCombination
|
|
|
|
return {width: photo.metadata.size.height, height: photo.metadata.size.width};
|
|
|
|
}
|
|
|
|
return photo.metadata.size;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const calcRotatedAspectRatio = (photo: PhotoDTO): number => {
|
|
|
|
const size = getRotatedSize(photo);
|
|
|
|
return size.width / size.height;
|
|
|
|
};
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|