Skip to content

Commit be9d22f

Browse files
committed
Fixed some errors
1 parent ec9a0b0 commit be9d22f

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ npm i ts-image-processor -S
3636
```
3737
import { getBlobForFile, imageProcessor, resize, sharpen, output } from 'ts-image-processor';
3838
39-
// Optionally convert File-object to blob (base64-string), e.g. if you have a file from <input>
39+
// If you have a file from <input>, convert it to base64-string first
4040
getBlobForFile(file).then(base64 => {
4141
// Use any of the functions with an existing blob (base64-string)
42-
imageProcessor.src(base64)
42+
imageProcessor
43+
.src(base64)
4344
.pipe(
4445
resize({maxWidth: 800, maxHeight: 800}),
4546
sharpen(),

demo/src/app/app.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ <h3>Resize & sharpen</h3>
5252
</div>
5353

5454
<div class="col-12 col-md-6">
55-
<ng-container *ngIf="resizeIsLoading || resizeImgResult">
56-
<small *ngIf="resizeIsLoading">Processing...</small>
55+
<ng-container *ngIf="resizeIsProcessing || resizeImgResult">
56+
<small *ngIf="resizeIsProcessing">Processing...</small>
5757
<ng-container *ngIf="resizeImgResult">
5858
<img [src]="resizeImgResult" alt="source" class="img-fluid">
5959
<div *ngIf="resizeProcessingTime">
@@ -97,8 +97,8 @@ <h3>Rotate & mirror</h3>
9797
</div>
9898
</div>
9999
<div class="col-12 col-md-6">
100-
<ng-container *ngIf="rotateIsLoading || rotateImgResult">
101-
<small *ngIf="resizeIsLoading">Processing...</small>
100+
<ng-container *ngIf="rotateIsProcessing || rotateImgResult">
101+
<small *ngIf="rotateIsProcessing">Processing...</small>
102102
<ng-container *ngIf="rotateImgResult">
103103
<img [src]="rotateImgResult" alt="source" class="img-fluid">
104104
<div *ngIf="rotateProcessingTime">

demo/src/app/app.component.ts

+36-20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
resize,
55
sharpen,
66
rotate,
7+
mirror,
78
output,
89
imageProcessor,
910
applyExifOrientation,
@@ -22,10 +23,10 @@ export class AppComponent implements OnInit {
2223

2324
applyExifOrientation: boolean;
2425
resizeImgResult: string;
25-
resizeIsLoading: boolean;
26+
resizeIsProcessing: boolean;
2627
resizeProcessingTime: number;
2728
rotateImgResult: string;
28-
rotateIsLoading: boolean;
29+
rotateIsProcessing: boolean;
2930
rotateProcessingTime: number;
3031

3132
onFileInputChange(file: File) {
@@ -68,10 +69,11 @@ export class AppComponent implements OnInit {
6869
return;
6970
}
7071

71-
this.resizeIsLoading = true;
72-
const t0 = performance.now();
72+
this.resizeIsProcessing = true;
73+
const t0 = performance.now();
7374

74-
imageProcessor.src(this.srcBase64)
75+
imageProcessor
76+
.src(this.srcBase64)
7577
.pipe(
7678
resize({
7779
maxWidth: +maxWidth,
@@ -84,31 +86,45 @@ export class AppComponent implements OnInit {
8486
).then(resultBase64 => {
8587
const t1 = performance.now();
8688
this.resizeProcessingTime = Math.round((t1 - t0) * 100) / 100;
87-
this.resizeIsLoading = false;
89+
this.resizeIsProcessing = false;
8890
this.resizeImgResult = resultBase64;
8991
},
9092
)
9193
;
9294
}
9395

9496
onRotate() {
95-
// const t0 = performance.now();
96-
//
97-
// rotate(this.rotateImgResult).then(blob => {
98-
// const t1 = performance.now();
99-
// this.rotateProcessingTime = Math.round((t1 - t0) * 100) / 100;
100-
// this.rotateImgResult = blob;
101-
// });
97+
const t0 = performance.now();
98+
99+
imageProcessor
100+
.src(this.rotateImgResult)
101+
.pipe(
102+
rotate(),
103+
output(),
104+
)
105+
.then(base64 => {
106+
const t1 = performance.now();
107+
this.rotateProcessingTime = Math.round((t1 - t0) * 100) / 100;
108+
this.rotateImgResult = base64;
109+
})
110+
;
102111
}
103112

104113
onMirror() {
105-
// const t0 = performance.now();
106-
//
107-
// mirror(this.rotateImgResult).then(blob => {
108-
// const t1 = performance.now();
109-
// this.rotateProcessingTime = Math.round((t1 - t0) * 100) / 100;
110-
// this.rotateImgResult = blob;
111-
// });
114+
const t0 = performance.now();
115+
116+
imageProcessor
117+
.src(this.rotateImgResult)
118+
.pipe(
119+
mirror(),
120+
output(),
121+
)
122+
.then(base64 => {
123+
const t1 = performance.now();
124+
this.rotateProcessingTime = Math.round((t1 - t0) * 100) / 100;
125+
this.rotateImgResult = base64;
126+
})
127+
;
112128
}
113129

114130
ngOnInit() {

src/lib/operators/mirror.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { base64ToImgElement } from '../utils';
44

55
// Need img/canvas source
66
// Need width/height
7-
function mirror(): OperatorFunction {
7+
export function mirror(): OperatorFunction {
88
return (base64: string) => {
99
return new Promise(resolve => {
1010
base64ToImgElement(base64).then(image => {

src/lib/operators/rotate.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import { base64ToImgElement } from '../utils';
1111
export function rotate(options: RotateOptions = {}): OperatorFunction {
1212
return (base64: string) => {
1313
return new Promise<string>(resolve => {
14+
const t0 = performance.now();
1415
base64ToImgElement(base64).then(image => {
1516
CanvasService.setSize(image.height, image.width);
1617
CanvasService.canvasCtx.rotate(90 * Math.PI / 180);
1718
CanvasService.canvasCtx.translate(0, -CanvasService.canvas.width);
1819
CanvasService.canvasCtx.drawImage(image.imgElement, 0, 0);
20+
const t1 = performance.now();
1921
resolve(CanvasService.canvas.toDataURL());
22+
console.log(t1-t0);
2023
});
2124
});
2225
};

0 commit comments

Comments
 (0)