From e93e75221ecc19832d9f98e97475b6ebb2f4f110 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 31 Oct 2021 08:47:23 +0100 Subject: [PATCH] Add scaling of full image view depending on aspect ratio Signed-off-by: trivernis --- .../components/file-gallery/file-gallery.component.html | 6 ++++-- .../components/file-gallery/file-gallery.component.scss | 9 +++++++++ .../components/file-gallery/file-gallery.component.ts | 8 ++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html index 76e3127..18984fd 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.html @@ -4,11 +4,13 @@
-
+
- Image + Image
diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.scss b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.scss index 00a5cc0..92aade4 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.scss +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.scss @@ -44,6 +44,15 @@ img { margin: auto; } +.align-width { + width: 100%; + height: auto; +} +.align-height { + height: 100%; + width: auto; +} + .close-button { position: absolute; top: 0; diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts index 468bc39..b241a1a 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery.component.ts @@ -30,6 +30,7 @@ export class FileGalleryComponent implements OnChanges, OnInit { selectedFile: Selectable | undefined; fileContentUrl: SafeResourceUrl | undefined; + scaleWidth = false; constructor(private fileService: FileService) { } @@ -131,4 +132,11 @@ export class FileGalleryComponent implements OnChanges, OnInit { } return undefined; } + + public adjustImageSize(fullImage: HTMLImageElement, imageContainer: HTMLDivElement): void { + const containerRatio = imageContainer.clientHeight / imageContainer.clientWidth; + const imageAdjHeight = fullImage.height / containerRatio; + const imageAdjWidth = fullImage.width * containerRatio; + this.scaleWidth = imageAdjWidth > imageAdjHeight; + } }