Make all images content aware

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 79bcf7c528
commit d3c94bc1ec

@ -1581,7 +1581,7 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.1.0" 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 = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
@ -2488,9 +2488,9 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.7.2" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f68b5ec0f51d53896979bb5364c10c6b0edf753b56570f1f2425b24ea6e85955" checksum = "17b727984a9179fbacb650930ae09537e06d50ce4fd767b0ce8b5a605f332199"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"rmp-serde", "rmp-serde",

@ -30,7 +30,7 @@ features = ["env-filter"]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "c944cf5d770ac895bd01464c92d41005055c0580" rev = "0b51564a518f4d7301107a83bd74b747b775b4f8"
features = ["tauri-plugin"] features = ["tauri-plugin"]
[features] [features]

@ -41,6 +41,7 @@ import {MatProgressSpinnerModule} from "@angular/material/progress-spinner";
import {BlockUIModule} from "primeng/blockui"; import {BlockUIModule} from "primeng/blockui";
import {PanelModule} from "primeng/panel"; import {PanelModule} from "primeng/panel";
import {DragDropModule} from "@angular/cdk/drag-drop"; import {DragDropModule} from "@angular/cdk/drag-drop";
import { ContentAwareImageComponent } from './components/content-aware-image/content-aware-image.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -56,6 +57,7 @@ import {DragDropModule} from "@angular/cdk/drag-drop";
FilterDialogComponent, FilterDialogComponent,
FileGalleryComponent, FileGalleryComponent,
FileGalleryEntryComponent, FileGalleryEntryComponent,
ContentAwareImageComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

@ -0,0 +1,6 @@
<div #imageContainer class="image-container">
<img #image [src]="this.imageSrc" alt="" (load)="this.adjustSize(image, imageContainer)"
(window:resize)="this.adjustSize(image, imageContainer)"
[class.scale-width]="scaleWidth" [class.scale-height]="!scaleWidth"
decoding="async">
</div>

@ -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;
}

@ -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<ContentAwareImageComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ContentAwareImageComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ContentAwareImageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -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;
}
}

@ -1,4 +1,4 @@
<div class="image-wrapper" (click)="fileSelectEvent.emit(this.file)" [class.selected]="this.file.selected"> <div class="image-wrapper" (click)="fileSelectEvent.emit(this.file)" [class.selected]="this.file.selected">
<mat-progress-spinner *ngIf="!contentUrl"></mat-progress-spinner> <mat-progress-spinner *ngIf="!contentUrl"></mat-progress-spinner>
<img [src]="contentUrl"> <app-content-aware-image *ngIf="contentUrl" [imageSrc]="contentUrl"></app-content-aware-image>
</div> </div>

@ -1,8 +1,6 @@
img { app-content-aware-image {
max-height: 100%; height: 100%;
max-width: 100%; width: 100%;
width: auto;
margin: auto;
} }
.image-wrapper { .image-wrapper {

@ -8,9 +8,7 @@
<div *ngIf="!this.fileContentUrl" class="url-loading-backdrop"> <div *ngIf="!this.fileContentUrl" class="url-loading-backdrop">
<mat-progress-spinner mode="indeterminate" color="primary"></mat-progress-spinner> <mat-progress-spinner mode="indeterminate" color="primary"></mat-progress-spinner>
</div> </div>
<img #fullImage *ngIf="this.fileContentUrl" (load)="this.adjustImageSize(fullImage, imageContainer)" (window:resize)="adjustImageSize(fullImage, imageContainer)" <app-content-aware-image *ngIf="this.fileContentUrl" [imageSrc]="this.fileContentUrl"></app-content-aware-image>
[class.align-width]="this.scaleWidth" [class.align-height]="!this.scaleWidth"
[src]="this.fileContentUrl" decoding="async" alt="Image"/>
</div> </div>
</div> </div>
<mat-divider fxFlex></mat-divider> <mat-divider fxFlex></mat-divider>

@ -37,20 +37,9 @@ app-file-gallery-entry {
position: relative; position: relative;
} }
img { app-content-aware-image {
max-height: 100%;
width: auto;
display: block;
margin: auto;
}
.align-width {
width: 100%;
height: auto;
}
.align-height {
height: 100%; height: 100%;
width: auto; width: 100%;
} }
.close-button { .close-button {

@ -1,7 +1,7 @@
<mat-card #card (click)="clickEvent.emit(this)" (dblclick)="dblClickEvent.emit(this)" [ngClass]="{'selected': gridEntry.selected}"> <mat-card #card (click)="clickEvent.emit(this)" (dblclick)="dblClickEvent.emit(this)" [ngClass]="{'selected': gridEntry.selected}">
<mat-card-title *ngIf="!!gridEntry.file?.name">{{gridEntry.file?.name}}</mat-card-title> <mat-card-title *ngIf="!!gridEntry.file?.name">{{gridEntry.file?.name}}</mat-card-title>
<mat-card-content *ngIf="contentUrl !== undefined"> <mat-card-content *ngIf="contentUrl !== undefined">
<img *ngIf="contentUrl !== undefined" class="entry-image" loading="lazy" decoding="async" [src]="contentUrl" alt="File Image"> <app-content-aware-image class="entry-image" *ngIf="contentUrl" [imageSrc]="contentUrl"></app-content-aware-image>
</mat-card-content> </mat-card-content>
<mat-card-footer> <mat-card-footer>
<mat-progress-bar *ngIf="contentUrl === undefined" mode="indeterminate"></mat-progress-bar> <mat-progress-bar *ngIf="contentUrl === undefined" mode="indeterminate"></mat-progress-bar>

@ -8,13 +8,9 @@ mat-card {
mat-card-content { mat-card-content {
height: 100%; height: 100%;
width: 100%; width: 100%;
justify-content: center;
text-align: center;
} }
.entry-image { .entry-image {
max-width: 100%; width: 100%;
max-height: 100%; height: 100%;
height: auto;
margin: auto;
} }

@ -10,4 +10,5 @@ app-file-grid-entry {
.file-row { .file-row {
display: flex; display: flex;
flex-direction: row;
} }

Loading…
Cancel
Save