# ng-img-editor

> An image cropper for Angular

Latest version **1.2.3** (published 2023-04-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng-img-editor
pnpm add ng-img-editor
yarn add ng-img-editor
bun add ng-img-editor
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2023-04-06 |
| First published | 2022-09-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 232.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeffrey K. D. A. Amoah |
| Maintainers | jay.dabo |
| Keywords | angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, image, image editor, photo editor, editor, cropper, ng-image-cropper-js, ngx-cropper, angular cropper, angular photo editor, angular image cropper, ngx, ng image editor, ngx cropper, image cropper, popup cropper |

## Links

- npm: https://www.npmjs.com/package/ng-img-editor
- Repository: https://github.com/Jay-Dabo/ng-img-editor
- Issues: https://github.com/Jay-Dabo/ng-img-editor/issues
- npm.io page: https://npm.io/package/ng-img-editor

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [ng-image-cropper-js](https://npm.io/package/ng-image-cropper-js.md) ^1.5.15

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads
- [react-native-modal-translucent-axton](https://npm.io/package/react-native-modal-translucent-axton.md) — 4 weekly downloads

## Recent versions

- 1.2.3 (latest) — 2023-04-06
- 1.2.2 — 2023-04-06
- 1.0.7 — 2023-04-06
- 1.0.6 — 2023-04-05
- 1.0.5 — 2023-04-05
- 1.0.4 — 2023-04-05
- 1.0.3 — 2023-04-05
- 1.0.2 — 2023-04-05
- 1.0.1 — 2022-09-22
- 1.0.0 — 2022-09-22
- 0.4.6 — 2022-09-21
- 0.4.5 — 2022-09-21
- 0.4.4 — 2022-09-21
- 0.4.3 — 2022-09-21

## README

# Image Cropper for Angular
[![NPM version][npm-img]][npm-url]
[![The MIT License][license-img]][license]
[![The MIT License][downloads-img]][downloads]


## Features

- NgImgEditor Component Injection without being passed  `ViewContainerRef`
- High performance
- Highly configurable and customizable
- Overridable styles
- Fully Supported

## Install

```bash  
   npm install ng-img-editor --save  
   
   or

   yarn add ng-img-editor
```
## Setup
#### Step 1:
- Import CSS.
```css
@import "~ng-img-editor/photo-editor.css";
``` 
-   If you are using angular-cli you can add it to your angular.json
```
"styles": [
  "styles.scss",
  "node_modules/ng-img-editor/photo-editor.css" // try adding '../' if you're using angular cli before 6
]
```
#### Step 2:
- Add NgImgEditorModule to app.module.ts
```ts
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';
import {NgImgEditorModule} from "ng-img-editor";

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgImgEditorModule,
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
}

```
## Usage
```html  
<input type="file" (change)="fileChangeHandler($event)">
<img [src]="output?.base64" alt="">
```  

And add this to your .ts file:
```ts  
import {Component} from '@angular/core';
import {NgxCroppedEvent, NgImgEditorService} from "ng-img-editor";

@Component({...})
export class AppComponent {
  output?: NgxCroppedEvent;

  constructor(private service: NgImgEditorService) {}

  fileChangeHandler($event: any) {
    this.service.open($event, {
      aspectRatio: 4 / 3,
      autoCropArea: 1
    }).subscribe(data => {
      this.output = data;
    });
  }
}
```    

You can pass any supported type of parameters to `NgImgEditorService.open()` to open the cropper.  After click `Apply` button the observer will return an object with the cropped image as a Base64, Blob in its payload.

## Parameters
| Name | Type | Description|
|--|--|--|
| `source` |`FileEvent | File | Blob | string` |Only image URL string, image related sources are supported.|
|`options`|`check below para`|This is an optional parameter



## Options
| Name| Type| Default| Description|
|-|-|-|-|  
|`format`|string|source Image format| Output format (png, jpeg, webp, bmp, ico) (not all browsers support all types, png is always supported, others are optional)|
| `aspectRatio` | number    | `NaN`        | The width / height ratio (e.g. 1 / 1 for a square, 4 / 3, 16 / 9 ...)                                                                                                                                                                |  
| `resizeToWidth` | number    | 0 (disabled) | Cropped image will be resized to this width (in px)                                                                                                                                                                                  |  
| `resizeToHeight` | number    | 0 (disabled) | Cropped image will be resized to this height (in px)                                                                                                                                       |  
| `roundCropper` | boolean   | false        | Set this to true for a round cropper mask. Resulting image will still be square, use `border-radius: 100%` on resulting image to show it as round.                                                                                        |  
| `imageQuality` | number    | 92           | This only applies when using jpeg or webp as output format. Entering a number between 0 and 100 will determine the quality of the output image.                                                                                      |  
| `autoCrop` | boolean   | true         | Enable to crop the image automatically when initialized.                                                                                                                                                                             |  
| `autoCropArea` | number    | 1 (80% of the image)| A number between 0 and 1. Define the automatic cropping area size (percentage).                                                                                                                                                      |  
| `viewMode` | number    | 0            | Define the [ViewMode](#viewMode) of the cropper.                                                                                                                                                                                     |  
| `mask` | boolean   | true         | Show the black modal above the image and under the crop box.                                                                                                                                                                         |  
| `guides` | boolean   | true         | Show the dashed lines above the crop box.                                                                                                                                                                                            |  
| `centerIndicator` | boolean   | true         | Show the center indicator above the crop box.                                                                                                                                                                                        |   
| `scalable` | boolean   | true         | Enable to scale the image.                                                                                                                                                                                                           |  
| `zoomable` | boolean   | true         | Enable to zoom the image.                                                                                                                                                                                                            |  
| `cropBoxMovable` | boolean   | true         | Enable to move the crop box by dragging.                                                                                                                                                                                             |  
| `cropBoxResizable` | boolean   | true         | Enable to resize the crop box by dragging.                                                                                                                                                                                           |  
| `imageSmoothingEnabled` | boolean   | true         | Smooth image output.                                                                                                                                                                                                                 |  
| `imageSmoothingQuality` | string    | low         | quality of image smoothing, one of "low" or "medium", or "high".|
| `modalMaxWidth` | string    | '500px'| max-width property of the dialog container                                                                                                                                                                                                     |  
| `hideModalHeader` | boolean   | false        | Hide Modal Header.                                                                                                                                                                                                                   |    
|`applyBtnText`| string | Apply | Apply button text|
|`closeBtnText`| string | Close | Close button text|


## Interfaces
#### NgxCroppedEvent
| Property | Type | Description |  
| --  | --| -- |  
| base64 | string          | Base64 string of the cropped image |  
| file | file(Blob)      | Blob(File) of the cropped image |

### viewMode

- Type: `Number`
- Default: `0`
- Options:
  - `0`: no restrictions
  - `1`: restrict the crop box to not exceed the size of the canvas.
  - `2`: restrict the minimum canvas size to fit within the container. If the proportions of the canvas and the container differ, the minimum canvas will be surrounded by extra space in one of the dimensions.
  - `3`: restrict the minimum canvas size to fill fit the container. If the proportions of the canvas and the container are different, the container will not be able to fit the whole canvas in one of the dimensions.

Define the view mode of the cropper. If you set `viewMode` to `0`, the crop box can extend outside the canvas, while a value of `1`, `2` or `3` will restrict the crop box to the size of the canvas. A `viewMode` of `2` or `3` will additionally restrict the canvas to the container. Note that if the proportions of the canvas and the container are the same, there is no difference between `2` and `3`.


[npm-url]: https://www.npmjs.com/package/ng-img-editor
[npm-img]: https://img.shields.io/npm/v/ng-img-editor?style=flat-square
[license]:http://opensource.org/licenses/MIT
[license-img]:https://img.shields.io/badge/license-MIT-orange.svg?color=blue&style=flat-square
[downloads]:https://img.shields.io/npm/dt/ng-img-editor?style=flat-square
[downloads-img]:https://img.shields.io/npm/dt/ng-img-editor?style=flat-square

---
_Source: https://npm.io/package/ng-img-editor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
