Angular Crop Image Before Upload with Preview : In this article, we will talk about Angular crop picture before upload to the application . This post will give you straightforward illustration of Angular cropper model. you’ll learn picture upload with crop in Angular. This article goes in nitty gritty on Angular  picture upload with crop utilizing cropper.

In the event that you need to utilize picture transfer with crop, you can undoubtedly utilize ngx-image-cropper npm package. it will give you Cropping, Zooming, Scaling, and Preview usefulness while uploading time. it’s effectively use with your Angular.

In this model, I will give you bit by bit clarification how you can upload transfer in crop in Angular application.

Step 1: Create New App

Create Angular app using the following command :

ng new ngPicCrop

Step 2: Install Npm Packages : 

In this progression, we will introduce ngx-image-cropper npm package for upload picture crop work in precise.

npm install ngx-image-cropper --save

Step 3: Import ImageCropperModule

Now, here we will import ImageCropperModule from ngx-image-cropper and then we add on declarations part. so let’s update app.module.ts file as like bellow:


import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { ImageCropperModule } from 'ngx-image-cropper';
  declarations: [
  imports: [
  providers: [],
  bootstrap: [AppComponent]
export class AppModule { }


Step 4: Update Component ts File : 

Here, we will refresh app.component.ts document here, in this record we will compose fileChangeEvent(), imageCropped(), imageLoaded(), cropperReady() and loadImageFailed() that gave by ngx-image-cropper.

You can refresh as howl app.component.ts document.


import { Component } from '@angular/core';
import { ImageCroppedEvent } from 'ngx-image-cropper';
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
export class AppComponent {
  title = 'ngImageCrop';
  imageChangedEvent: any = '';
    croppedImage: any = '';
    fileChangeEvent(event: any): void {
        this.imageChangedEvent = event;
    imageCropped(event: ImageCroppedEvent) {
        this.croppedImage = event.base64;
    imageLoaded() {
        /* show cropper */
    cropperReady() {
        /* cropper ready */
    loadImageFailed() {
        /* show message */

Step 5: Update HTML File : 

<div class="container">
    <div class="card">
      <div class="card-header">
          Angular Crop Image Tutorial Example -
      <div class="card-body">
        <input type="file" (change)="fileChangeEvent($event)" />
        <div class="row" style="margin-top: 15px;">
            <div class="text-center col-md-8">
                <h5>Crop Image</h5>
                [aspectRatio]="4 / 4"
            <div class="text-center col-md-4">
                <img [src]="croppedImage" />

Now you run your Angular app by following command :

ng serve


Output :

Angular Crop Image Before Upload with Preview

Angular Crop Image Before Upload with Preview

Please follow and like us: