libs/upp-wdgt/src/components/upp-crop/upp-crop.ts
The UppCropComponent is an Angular component used for cropping images with a specified width and height.
It integrates with the ngx-img-cropper library and supports base64 image output.
The component includes features such as dynamic canvas resizing and aspect ratio preservation.
This component extends the languageSupport class, providing support for language services.
Ensure the height and width inputs are valid and greater than 0.
```html
<upp-crop-image
[image]="imageSource"
[height]="200"
[width]="200"
(Cropped)="onImageCropped($event)">
</upp-crop-image>
languageSupport
OnInit
AfterViewInit
OnDestroy
| selector | upp-crop-image |
| styleUrls | ./upp-crop.scss |
| templateUrl | ./upp-crop.html |
Properties |
|
Methods |
|
Inputs |
Outputs |
constructor(lang: languageService, change: ChangeDetectorRef)
|
||||||||||||
|
Constructs the
Parameters :
|
| height |
Type : number
|
Default value : 0
|
|
The desired height of the cropped image. Must be greater than 0. |
| image |
Type : any
|
Default value : null
|
|
Input image to be cropped. Can be of any type supported by the ngx-img-cropper library. |
| width |
Type : number
|
Default value : 0
|
|
The desired width of the cropped image. Must be greater than 0. |
| Cropped |
Type : EventEmitter
|
|
Emits the cropped image in base64 format. |
| ngAfterViewInit |
ngAfterViewInit()
|
|
Configures the cropper dimensions after the view is initialized.
Returns :
void
|
| ngOnDestroy |
ngOnDestroy()
|
|
Cleans up resources when the component is destroyed.
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Initializes the component by setting up the cropper settings and validating inputs.
Returns :
void
|
| Public OnCrop | ||||||||
OnCrop(bounds: any)
|
||||||||
|
Handles the crop event and stores the cropping bounds.
Parameters :
Returns :
void
|
| Public OnSave |
OnSave()
|
|
Emits the cropped image in base64 format to the parent component.
Returns :
void
|
| Public _croppedHeight |
Type : number
|
Default value : 0
|
|
Height of the cropped image in pixels. |
| Public _croppedImage |
Type : any
|
Default value : {}
|
|
Stores the cropped image data. |
| Public _croppedWidth |
Type : number
|
Default value : 0
|
|
Width of the cropped image in pixels. |
| Public _cropperSettings |
Type : CropperSettings | null
|
Default value : null
|
|
Configuration settings for the image cropper. These settings control the cropper's behavior and appearance. |
<div #cropbox class="cropper-box">
<div *ngIf="_cropperSettings && _cropperSettings.canvasWidth !== 0">
<img-cropper #cropper uppDataid="cropper-image" [image]="_croppedImage" [settings]="_cropperSettings" (onCrop)="OnCrop($event)"></img-cropper>
</div>
</div>
<ion-button uppDataid="cropper-submit" size="large" expand="block" color="primary" (click)="OnSave()">
{{tr('@crop_accept_changes')}}
</ion-button>
./upp-crop.scss
.cropper-box {
position: relative;
width: 100%;
height: 400px;
border-radius: 6px;
overflow: hidden;
}