Add parameter to specify the decoding strategy on content-aware-images

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 03cdc3ea0c
commit 448d55aa1e

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

@ -1,4 +1,4 @@
import {Component, Input} from '@angular/core'; import {Component, ElementRef, Input, OnInit, ViewChild} from '@angular/core';
import {SafeResourceUrl} from "@angular/platform-browser"; import {SafeResourceUrl} from "@angular/platform-browser";
@Component({ @Component({
@ -6,17 +6,26 @@ import {SafeResourceUrl} from "@angular/platform-browser";
templateUrl: './content-aware-image.component.html', templateUrl: './content-aware-image.component.html',
styleUrls: ['./content-aware-image.component.scss'] styleUrls: ['./content-aware-image.component.scss']
}) })
export class ContentAwareImageComponent { export class ContentAwareImageComponent implements OnInit {
@Input() imageSrc!: string | SafeResourceUrl; @Input() imageSrc!: string | SafeResourceUrl;
@Input() maximizeHeight: boolean = true; @Input() maximizeHeight: boolean = true;
@Input() maximizeWidth: boolean = true; @Input() maximizeWidth: boolean = true;
@Input() decoding: "async" | "sync" | "auto" = "auto";
@ViewChild("image") image: ElementRef<HTMLImageElement> | undefined;
scaleWidth = false; scaleWidth = false;
constructor() { constructor() {
} }
public ngOnInit(): void {
if (this.image) {
this.image.nativeElement.decoding = this.decoding;
}
}
/** /**
* Fits the image into the container * Fits the image into the container
* @param {HTMLImageElement} image * @param {HTMLImageElement} image

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

@ -19,7 +19,7 @@
<div #imageDragContainer (cdkDragMoved)="this.onDragMoved($event)" *ngIf="this.fileContentUrl" <div #imageDragContainer (cdkDragMoved)="this.onDragMoved($event)" *ngIf="this.fileContentUrl"
[cdkDragFreeDragPosition]="this.imagePosition" cdkDrag class="image-drag-container"> [cdkDragFreeDragPosition]="this.imagePosition" cdkDrag class="image-drag-container">
<div #scaledImage [style]="{scale: this.imageZoom}" class="image-scale-container"> <div #scaledImage [style]="{scale: this.imageZoom}" class="image-scale-container">
<app-content-aware-image [imageSrc]="this.fileContentUrl"></app-content-aware-image> <app-content-aware-image [imageSrc]="this.fileContentUrl" decoding="sync"></app-content-aware-image>
</div> </div>
</div> </div>
</div> </div>

@ -1,7 +1,7 @@
<mat-card #card (click)="clickEvent.emit(this)" (dblclick)="dblClickEvent.emit(this)" <mat-card #card (click)="clickEvent.emit(this)" (dblclick)="dblClickEvent.emit(this)"
[ngClass]="{'selected': gridEntry.selected}"> [ngClass]="{'selected': gridEntry.selected}">
<mat-card-content *ngIf="contentUrl !== undefined"> <mat-card-content *ngIf="contentUrl !== undefined">
<app-content-aware-image *ngIf="contentUrl" [imageSrc]="contentUrl" class="entry-image"></app-content-aware-image> <app-content-aware-image decoding="async" *ngIf="contentUrl" [imageSrc]="contentUrl" class="entry-image"></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>

Loading…
Cancel
Save