Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-document-scanner

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-document-scanner

Angular 2+ component for cropping and enhancing images of documents

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
52
increased by246.67%
Maintainers
1
Weekly downloads
 
Created
Source

Ngx Document Scanner

An Angular component for cropping and enhancing images of documents, for implementation on a mobile or desktop app.
It uses a WASM build of OpenCV to manipulate images, to achieve near-native performance. Note that there are a few extra steps required to configure the component other than installing the package from npm.

Live Demo

View a live demo here

Installation & Setup

install the package via npm

npm install ngx-document-scanner --save

the UI is based on @angular/material, if you don't have it installed:

ng add @angular/material 

choose 'yes' when prompted if you wish to add angular animations as it is needed for some of the components.

Configure OpenCV

copy the opencv.js files to your assets folder (or any other folder). you can build the files yourself (instructions on the OpenCV site), or download them from this package's repository. both opencv.js & opencv_js.wasm need to placed in the same folder.

import the package to your app.module. you'll need to configure the location of the open cv files.

import {OpenCVConfig} from 'ngx-document-scanner';
import {NgxDocumentScannerModule} from 'ngx-document-scanner';

// set the location of the OpenCV files
const openCVConfig: OpenCVConfig = {
  openCVDirPath: '/assets/opencv'  
};

@NgModule({ imports: 
  [NgxDocumentScannerModule.forRoot(openCVConfig)],
  bootstrap: [AppComponent]  
})
export class AppModule { }

Usage

add component to template and bind to inputs and outputs.
<ngx-doc-scanner 
     *ngIf="image"
     [file]="image"
     [config]="config">
     (editResult)="editResult($event)"
     (exitEditor)="exitEditor($event)"
     (error)="onError($event)"
     (processing)="editorState($event)"
</ngx-doc-scanner>
set configuration options. for example:
config: DocScannerConfig = {  
    editorBackgroundColor: '#fafafa', 
    buttonThemeColor: 'primary',  
    cropToolColor: '#ff4081',  
    cropToolShape: 'circle',
    exportImageIcon: 'cloud_download'  
};

Component I\O

Inputs

inputtypedescription
fileFilesets an image for editing
configDocScannerConfigconfiguration object for the component. see section dedicated to te config object.

Outputs

outputtypedescription
errorEventEmitter<any>fires on error
editResultEventEmitter<Blob>fires when the users submits the image
exitEditorEventEmitter<any>fires when the user exits the editor
processingEventEmitter<boolean>fires true when the editor is prcessing or loading\parsing the OpenCV module.

Configuration Object

optional configuration values that can be passed to the component.

import {DocScannerConfig} form 'ngx-document-scanner'
config: DocScannerConfig = {
    ....
}
propertytypedescription
buttonThemeColor"primary" | "warn" | "accent"material design theme color name for the buttons on the component
cropToolColorstringcolor of the crop tool (points and connecting lines)
cropToolDimensions{width: number; height: nubmer;}width and height of the crop tool points
cropToolLineWeightnumberweight of the crop tool's connecting lines
cropToolShape'rect' &#124; 'circle'shape of the crop tool points
editorBackgroundColorstringbackground color of the main editor div
editorDimensionsan object of css keys value pairscss properties for the main editor div
exportImageIconstringicon for the button that completes the editing and emits the edited image.
extraCssan object of css keys value pairscss that will be added to the main div of the editor component
maxImageDimensions{width: number; height: nubmer;}max dimensions of oputput image. if set to zero will not resize the image.
maxPreviewWidthnumbermax width of the preview pane

Ngx-OpenCV

The angular service used to load the open cv library and monitor it's state is also available as a standalone package: NgxOpenCV

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 27 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc