From d3c94bc1ec3a8ddf3861dc5884ff5e4db44c0ef6 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 31 Oct 2021 13:06:19 +0100 Subject: [PATCH] Make all images content aware Signed-off-by: trivernis --- mediarepo-ui/src-tauri/Cargo.lock | 6 ++-- mediarepo-ui/src-tauri/Cargo.toml | 2 +- mediarepo-ui/src/app/app.module.ts | 2 ++ .../content-aware-image.component.html | 6 ++++ .../content-aware-image.component.scss | 19 ++++++++++++ .../content-aware-image.component.spec.ts | 25 +++++++++++++++ .../content-aware-image.component.ts | 31 +++++++++++++++++++ .../file-gallery-entry.component.html | 2 +- .../file-gallery-entry.component.scss | 8 ++--- .../file-gallery/file-gallery.component.html | 4 +-- .../file-gallery/file-gallery.component.scss | 15 ++------- .../file-grid-entry.component.html | 2 +- .../file-grid-entry.component.scss | 8 ++--- .../file-grid/file-grid.component.scss | 1 + 14 files changed, 98 insertions(+), 33 deletions(-) create mode 100644 mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html create mode 100644 mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.scss create mode 100644 mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.spec.ts create mode 100644 mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts diff --git a/mediarepo-ui/src-tauri/Cargo.lock b/mediarepo-ui/src-tauri/Cargo.lock index e91d1dd..741ce03 100644 --- a/mediarepo-ui/src-tauri/Cargo.lock +++ b/mediarepo-ui/src-tauri/Cargo.lock @@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "mediarepo-api" version = "0.1.0" -source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=c944cf5d770ac895bd01464c92d41005055c0580#c944cf5d770ac895bd01464c92d41005055c0580" +source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=0b51564a518f4d7301107a83bd74b747b775b4f8#0b51564a518f4d7301107a83bd74b747b775b4f8" dependencies = [ "async-trait", "chrono", @@ -2488,9 +2488,9 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.7.2" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" +checksum = "17b727984a9179fbacb650930ae09537e06d50ce4fd767b0ce8b5a605f332199" dependencies = [ "lazy_static", "rmp-serde", diff --git a/mediarepo-ui/src-tauri/Cargo.toml b/mediarepo-ui/src-tauri/Cargo.toml index 167e9c3..8a9eb52 100644 --- a/mediarepo-ui/src-tauri/Cargo.toml +++ b/mediarepo-ui/src-tauri/Cargo.toml @@ -30,7 +30,7 @@ features = ["env-filter"] [dependencies.mediarepo-api] git = "https://github.com/Trivernis/mediarepo-api.git" -rev = "c944cf5d770ac895bd01464c92d41005055c0580" +rev = "0b51564a518f4d7301107a83bd74b747b775b4f8" features = ["tauri-plugin"] [features] diff --git a/mediarepo-ui/src/app/app.module.ts b/mediarepo-ui/src/app/app.module.ts index d1dd417..cc10402 100644 --- a/mediarepo-ui/src/app/app.module.ts +++ b/mediarepo-ui/src/app/app.module.ts @@ -41,6 +41,7 @@ import {MatProgressSpinnerModule} from "@angular/material/progress-spinner"; import {BlockUIModule} from "primeng/blockui"; import {PanelModule} from "primeng/panel"; import {DragDropModule} from "@angular/cdk/drag-drop"; +import { ContentAwareImageComponent } from './components/content-aware-image/content-aware-image.component'; @NgModule({ declarations: [ @@ -56,6 +57,7 @@ import {DragDropModule} from "@angular/cdk/drag-drop"; FilterDialogComponent, FileGalleryComponent, FileGalleryEntryComponent, + ContentAwareImageComponent, ], imports: [ BrowserModule, 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 new file mode 100644 index 0000000..ac6d466 --- /dev/null +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.html @@ -0,0 +1,6 @@ +
+ +
diff --git a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.scss b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.scss new file mode 100644 index 0000000..8db781a --- /dev/null +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.scss @@ -0,0 +1,19 @@ +.image-container { + height: 100%; + width: 100%; + display: flex; +} + +.image-container > img { + margin: auto; +} + +img.scale-height { + height: 100%; + width: auto; +} + +img.scale-width { + width: 100%; + height: auto; +} diff --git a/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.spec.ts b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.spec.ts new file mode 100644 index 0000000..0aaef2b --- /dev/null +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ContentAwareImageComponent } from './content-aware-image.component'; + +describe('ContentAwareImageComponent', () => { + let component: ContentAwareImageComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ContentAwareImageComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ContentAwareImageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 0000000..183e301 --- /dev/null +++ b/mediarepo-ui/src/app/components/content-aware-image/content-aware-image.component.ts @@ -0,0 +1,31 @@ +import {Component, Input, OnInit} from '@angular/core'; +import {SafeResourceUrl} from "@angular/platform-browser"; + +@Component({ + selector: 'app-content-aware-image', + templateUrl: './content-aware-image.component.html', + styleUrls: ['./content-aware-image.component.scss'] +}) +export class ContentAwareImageComponent { + + @Input() imageSrc!: string | SafeResourceUrl; + + scaleWidth = false; + + constructor() { } + + /** + * Fits the image into the container + * @param {HTMLImageElement} image + * @param {HTMLDivElement} imageContainer + */ + public adjustSize(image: HTMLImageElement, imageContainer: HTMLDivElement): void { + const containerHeight = Math.abs(imageContainer.clientHeight); + const containerWidth = Math.abs(imageContainer.clientWidth); + console.log(containerHeight, ',', containerWidth); + const imageRelativeHeight = image.height / containerHeight; + const imageRelativeWidth = image.width / containerWidth; + console.log(imageRelativeHeight, ',', imageRelativeWidth); + this.scaleWidth = imageRelativeWidth > imageRelativeHeight; + } +} diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.html b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.html index cf26cee..1324653 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.html +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.html @@ -1,4 +1,4 @@
- +
diff --git a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.scss b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.scss index 3cf660c..ee1eebc 100644 --- a/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.scss +++ b/mediarepo-ui/src/app/components/file-gallery/file-gallery-entry/file-gallery-entry.component.scss @@ -1,8 +1,6 @@ -img { - max-height: 100%; - max-width: 100%; - width: auto; - margin: auto; +app-content-aware-image { + height: 100%; + width: 100%; } .image-wrapper { 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 b32b076..f4a3a4a 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 @@ -8,9 +8,7 @@
- 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 92aade4..7eec01d 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 @@ -37,20 +37,9 @@ app-file-gallery-entry { position: relative; } -img { - max-height: 100%; - width: auto; - display: block; - margin: auto; -} - -.align-width { - width: 100%; - height: auto; -} -.align-height { +app-content-aware-image { height: 100%; - width: auto; + width: 100%; } .close-button { diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html index 8aec515..465c3b5 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html +++ b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.html @@ -1,7 +1,7 @@ {{gridEntry.file?.name}} - File Image + diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss index 636b936..55469d6 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss +++ b/mediarepo-ui/src/app/components/file-grid/file-grid-entry/file-grid-entry.component.scss @@ -8,13 +8,9 @@ mat-card { mat-card-content { height: 100%; width: 100%; - justify-content: center; - text-align: center; } .entry-image { - max-width: 100%; - max-height: 100%; - height: auto; - margin: auto; + width: 100%; + height: 100%; } diff --git a/mediarepo-ui/src/app/components/file-grid/file-grid.component.scss b/mediarepo-ui/src/app/components/file-grid/file-grid.component.scss index dc20e1c..dbc6e20 100644 --- a/mediarepo-ui/src/app/components/file-grid/file-grid.component.scss +++ b/mediarepo-ui/src/app/components/file-grid/file-grid.component.scss @@ -10,4 +10,5 @@ app-file-grid-entry { .file-row { display: flex; + flex-direction: row; }