Last active
June 29, 2024 14:09
-
-
Save tnqsoft/38aed9ee97d200bb899f61e68ebb2a9d to your computer and use it in GitHub Desktop.
Revisions
-
tnqsoft revised this gist
Jul 13, 2017 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,7 @@ <div *ngFor="let item of uploader.queue; let first = first;"> <img src="" thumbnail [image]="item?._file"/> {{ item?.file?.name }} {{ item?.file?.size }} </div> <input type="file" ng2FileSelect [uploader]="uploader" #fileInput [accept]="accept.toString()" [multiple]="multiple"/> -
tnqsoft renamed this gist
Jul 13, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
tnqsoft created this gist
Jul 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ <img src="" thumbnail [image]="item?._file"/> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ import { Directive, ElementRef, Input, Renderer, OnChanges, SimpleChanges } from '@angular/core'; @Directive({ selector: 'img[thumbnail]' }) export class ThumbnailDirective { @Input() public image: any; constructor(private el: ElementRef, private renderer: Renderer) { } public ngOnChanges(changes: SimpleChanges) { let reader = new FileReader(); let el = this.el; reader.onloadend = (readerEvent) => { let image = new Image(); image.onload = (imageEvent) => { // Resize the image let canvas = document.createElement('canvas'); let maxSize = 70; let width = image.width; let height = image.height; if (width > height) { if (width > maxSize) { height *= maxSize / width; width = maxSize; } } else { if (height > maxSize) { width *= maxSize / height; height = maxSize; } } canvas.width = width; canvas.height = height; canvas.getContext('2d').drawImage(image, 0, 0, width, height); el.nativeElement.src = canvas.toDataURL('image/jpeg'); }; image.src = reader.result; }; if (this.image) { return reader.readAsDataURL(this.image); } } }