Getting Started - Angular
Let's get started!#
Free Trial#
Our tech is modified to be used for testing purposes without a license key. To start testing just follow this Get Started guide and leave out the step of entering the commercial license keys. The editor will simply render a watermark over the preview and final results. And in case you need any technical assistance, make sure to reach out to us: https://img.ly/support. We’ll be glad to help.
We will be using angular cli for simplicity.
Create a project#
- Start a new project by following the
angular cli
prompts
ng new my-appcd my-appng serve
- Then open
http://localhost:4200/
to see your app.
Installing peer dependencies#
PhotoEditor SDK needs following peer dependencies:
- React >= 16.8.6
- React DOM >= 16.8.6
- Styled Components >= 4.4
- Run
npm install --save react react-dom styled-components
to include them in the project. - Run
npm install --save-dev @types/react @types/react-dom
to include the types in the project. - Add
"allowSyntheticDefaultImports": true
to thecompilerOptions
intsconfig.json
in order to compile React.
Installing PhotoEditor SDK#
- Run
npm install --save photoeditorsdk
. - Copy the contents from
node_modules/photoeditorsdk/assets
tosrc/assets/photoeditorsdk
.
Creating an Editor component#
Use the angular cli
to generate the scaffold for your editor component.
ng generate component photo-editor
In contrast to the other frameworks, the editor needs to be imported from the photoeditorsdk/no-polyfills
entry point in Angular to avoid polyfill conflicts.
import {Component,AfterViewInit,ViewChild,Input,ElementRef,} from '@angular/core';import { PhotoEditorSDKUI, EditorApi } from 'photoeditorsdk/no-polyfills';const license = '';@Component({selector: 'app-photo-editor',templateUrl: './photo-editor.component.html',})export class PhotoEditorComponent implements AfterViewInit {@Input()public src: string = '';@ViewChild('psdkContainer', { static: false })private container: ElementRef<HTMLDivElement> | null = null;public editor: EditorApi | null = null;ngAfterViewInit() {this.initEditor();}async initEditor() {try {if (this.editor) {this.editor.dispose();}this.editor = await PhotoEditorSDKUI.init({license,container: this.container ? this.container.nativeElement : '',image: this.src,assetBaseUrl: '/assets/photoeditorsdk',});} catch (error) {console.log(error);}}}
<div #psdkContainer style="width: 100vw; height: 100vh;"></div>
Add the component to the app#
<app-photo-editorsrc="https://img.ly/static/libraries/unsplash/raw/PZAxzN5DPkc.jpg"></app-photo-editor>
Related Pages#
ReferenceError: x is not defined
Error: process is not defined
- Angular and Zone.js
- Add polyfills to Angular
- AngularJS and IE11
- Supported Angular Versions
CORS#
If you are loading images from external sources (e.g. from an AWS bucket), you need to first configure Cross-Origin Resource Sharing for both the server and the image. Otherwise, you will see errors such as
Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at [...] may not be loaded.or Unable to get image data from canvas because the canvas has been tainted.Please follow the instructions on how to properly configure CORS here.
Ready to go!#
There you have it. PhotoEditor SDK for the Web is ready to use. Refer to the configuration documentaion for more configuration options.