From 309995db24847e5c73d448d0497f93955e59e9d3 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 3 Nov 2021 19:52:25 +0100 Subject: [PATCH] Fix scaling issues with images Signed-off-by: trivernis --- .../content-aware-image.component.html | 3 +-- .../content-aware-image.component.ts | 4 ++-- .../file-gallery-entry.component.ts | 12 +++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html index 7d82abe..5269d90 100644 --- a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html @@ -1,6 +1,5 @@ -
+
diff --git a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts index 86fa312..0ba383e 100644 --- a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts @@ -24,8 +24,8 @@ export class ContentAwareImageComponent { public adjustSize(image: HTMLImageElement, imageContainer: HTMLDivElement): void { const containerHeight = Math.abs(imageContainer.clientHeight); const containerWidth = Math.abs(imageContainer.clientWidth); - const imageRelativeHeight = image.height / containerHeight; - const imageRelativeWidth = image.width / containerWidth; + const imageRelativeHeight = image.naturalHeight / containerHeight; + const imageRelativeWidth = image.naturalWidth / containerWidth; this.scaleWidth = imageRelativeWidth > imageRelativeHeight; } } diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.ts b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.ts index a666b1e..242beed 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.ts +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.ts @@ -28,8 +28,11 @@ export class FileGalleryEntryComponent implements OnInit, OnChanges { constructor(private fileService: FileService, private errorBroker: ErrorBrokerService) { } async ngOnChanges(changes: SimpleChanges): Promise { - if (!this.cachedFile || this.file.data.hash !== this.cachedFile.hash) { // handle changes to the file when the component is not destroyed + if (changes["file"] && (!this.cachedFile || this.file.data.hash !== this.cachedFile!.hash)) { // handle changes to the file when the component is not destroyed this.cachedFile = this.file.data; + this.contentUrl = undefined; + await this.loadImage(); + } else if (!this.contentUrl) { await this.loadImage(); } } @@ -41,14 +44,17 @@ export class FileGalleryEntryComponent implements OnInit, OnChanges { async loadImage() { try { - const thumbnails = await this.fileService.getThumbnails(this.file.data.hash); + const hash = this.file.data.hash; + const thumbnails = await this.fileService.getThumbnails(hash); let thumbnail = thumbnails.find(t => (t.height > 250 || t.width > 250) && (t.height < 500 && t.width < 500)); thumbnail = thumbnail ?? thumbnails[0]; if (!thumbnail) { console.log("Thumbnail is empty?!", thumbnails); - } else { + } else if (this.file.data.hash === hash) { this.contentUrl = await this.fileService.readThumbnail(thumbnail!!); + } else { + console.warn("Grid file updated while loading thumbnail.") } } catch (err) { this.errorBroker.showError(err);