My latest project involved creating a custom cropper using ngx-image-cropper, which allows for cropping and rotating images. For the sprint demo, I needed the images to be displayed as soon as the application loads without having to trigger the fileChangeEvent() event in ngx-image-cropper.
The current outcome is functioning perfectly.
By clicking on one of the links (Photo - Signature - ...), the file uploader opens up allowing me to choose a photo to crop.
https://i.sstatic.net/83Rtv.png
This is what I aim to achieve:
Upon accessing the page initially, load a file directly from my disk without needing to click on any link.
https://i.sstatic.net/zEiKF.png
Note: I am working with Angular 8.
Below is the code snippet for the image cropper:
<mat-card-content style="padding:3% 5%; text-align: center;">
<image-cropper [ngClass]=" loaded && showCropper && !cropped ? 'showCropper' : 'hideCropper' "
[imageChangedEvent]="imageChangedEvent"
[maintainAspectRatio]="false"
[containWithinAspectRatio]="containWithinAspectRatio"
[aspectRatio]="5 / 3"
[cropperMinWidth]="128"
[onlyScaleDown]="true"
[roundCropper]="false"
[canvasRotation]="canvasRotation"
[transform]="transform"
[alignImage]="'center'"
[style.display]="showCropper ? null : 'none'"
format="png"
(imageCropped)="imageCropped($event)"
(imageLoaded)="imageLoaded()"
(cropperReady)="cropperReady($event)"
(loadImageFailed)="loadImageFailed()"
>
</image-cropper>
<img
*ngIf="loaded && !showCropper && cropped"
class="document-photo"
[src]="croppedImage"
/>
<div *ngIf="!loaded" class="divNone"></div>
<div class="icon-image">
<mat-icon (click)="rotateLeft()">rotate_left</mat-icon>
<mat-icon (click)="rotateRight()">rotate_right</mat-icon>
<mat-icon (click)="activateCrop()">crop</mat-icon>
<mat-icon (click)="clearImage()">clear</mat-icon>
<mat-icon (click)="validate()">check</mat-icon>
<mat-icon>note_add</mat-icon>
</div>
</mat-card-content>
<mat-list-item class="item-doc text-blue-in">
<mat-icon class="icon-info" matTooltipPosition="above" matTooltip="Info about the photo">info</mat-icon>
<mat-icon *ngIf="!photo" class="text-grey-in">check_box_outline_blank</mat-icon>
<mat-icon *ngIf="photo" class="text-grey-in">check_box</mat-icon>
<input style="visibility: hidden; display: none;" #linkPhoto type="file" (change)="fileChangeEvent($event, 'photo')"/>
<mat-label class="doc-title text-grey-in" (click)="onLoadPhoto()" >Photo</mat-label>
<mat-icon *ngIf="photoSent" class="icon-edit" (click)="editPhoto()">edit</mat-icon >
</mat-list-item>
So, my question is: How can I load an image from my disk into ngx-image-cropper without triggering the fileChangedEvent?