0.0.29 • Published 7 months ago
ngx-easy-image-drawing v0.0.29
ngx-easy-image-drawing
Angular library for easy image drawing on a canvas.
This library provides a simple and efficient way to allow users to draw on images within your Angular applications.
Installation
npm install ngx-easy-image-drawing
Usage
- Import
import { EasyImageDrawing } from "ngx-easy-image-drawing";
@NgModule({
imports: [EasyImageDrawing],
})
export class AppModule {}
- Use it in your template
<easy-image-drawing
[height]="canvasHeight"
[width]="canvasWidth"
[src]="uploadImageFilePreview"
(savedImage)="handleSavedImage($event)"
>
</easy-image-drawing>
Options
| Option | Type | Description |
| ------------------- | -------------------- | ------------------------------------------------------------------------------------------------- |
| height | number | The height of the canvas in pixels. |
| width | number | The width of the canvas in pixels. |
| src | string | The image source URL. |
| saveButtonColor | string | The backbackground color for save button (optional parameter). |
| undoButtonColor | string | The backbackground color for save button (optional parameter). |
| forceSizeExport | boolean | Whether to force the exported image size to match the canvas size (in the pipeline). |
| outputMimeType | string | The MIME type of the exported image (e.g., 'image/jpeg', 'image/png') (in the pipeline). |
| outputQuality | number | The quality of the exported image (0-1) (in the pipeline). |
| showColorPicker | boolean | Show color picker (optional parameter). True by default. |
| showlineWidthPicker | boolean | Show line width picker (optional parameter). True by default. |
| savedImage | EventEmitter<File> | An event emitted when the image is saved. The event payload is a data URL representing the image. |
Example
app.component.ts
import { Component } from "@angular/core";
import { RouterOutlet } from "@angular/router";
import { EasyImageDrawing } from "ngx-easy-image-drawing";
@Component({
selector: "app-root",
standalone: true,
imports: [RouterOutlet, EasyImageDrawing],
templateUrl: "./app.component.html",
styleUrl: "./app.component.css",
})
export class AppComponent {
title = "my-project";
canvasHeight = 600;
canvasWidth = 600;
uploadImageFilePreview: any = null;
savedImage: any = null;
onFileChange(event: any) {
const file = event.target.files[0];
const reader = new FileReader();
// readAsDataURL reads the uploaded file content and returns a string representing the image data encoded as a DataURL.
reader.readAsDataURL(file);
// The DataURL typically starts with a prefix like data:image/jpeg;base64,. This prefix specifies the image format (image/jpeg) and encoding (base64).
reader.onload = (e: any) => {
// By assigning the complete DataURL string to uploadImageFilePreview, you provide the necessary information to the easy-image-drawing component to display the uploaded image.
this.uploadImageFilePreview = e.target.result;
};
}
handleSavedImage(event: any) {
this.savedImage = event;
// reset the image preview
this.uploadImageFilePreview = null;
}
}
app.component.html
<!-- input image -->
<input type="file" (change)="onFileChange($event)" />
<!-- image preview -->
<!-- use ngIf to show the image drawing component only when the image is uploaded -->
@if(uploadImageFilePreview) {
<easy-image-drawing
[height]="canvasHeight"
[width]="canvasWidth"
[src]="uploadImageFilePreview"
[showColorPicker]="true"
[showlineWidthPicker]="true"
saveButtonColor="#4caf50"
undoButtonColor="#f44336"
(savedImage)="handleSavedImage($event)"
>
</easy-image-drawing>
}
0.0.29
7 months ago
0.0.28
11 months ago
0.0.27
11 months ago
0.0.26
12 months ago
0.0.25
12 months ago
0.0.24
12 months ago
0.0.23
12 months ago
0.0.22
12 months ago
0.0.21
12 months ago
0.0.20
12 months ago
0.0.19
12 months ago
0.0.18
12 months ago
0.0.17
12 months ago
0.0.16
12 months ago
0.0.15
12 months ago
0.0.14
12 months ago
0.0.13
12 months ago
0.0.12
12 months ago
0.0.11
12 months ago
0.0.10
12 months ago
0.0.9
12 months ago
0.0.8
12 months ago
0.0.7
12 months ago
0.0.6
12 months ago
0.0.5
12 months ago
0.0.4
12 months ago
0.0.3
12 months ago
0.0.2
12 months ago
0.0.1
12 months ago