@wemap/camera 9.0.8 → 10.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +1 -0
- package/package.json +2 -2
- package/src/CameraUtils.js +17 -0
package/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare module '@wemap/camera' {
|
|
|
19
19
|
): { vertical: number, horizontal: number };
|
|
20
20
|
static createCameraCalibrationFromWidthHeightFov(width: number, height: number, fovOfWidth: number): Calibration;
|
|
21
21
|
static canvasToBase64(canvas: HTMLCanvasElement, type?: string, quality?: any): string;
|
|
22
|
+
static base64ToCanvas(base64: string, type?: string): HTMLCanvasElement;
|
|
22
23
|
static convertToGrayscale(imageCanvas: HTMLCanvasElement): void;
|
|
23
24
|
static reduceImageSize(
|
|
24
25
|
imageCanvas: HTMLCanvasElement,
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/camera"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/camera",
|
|
15
|
-
"version": "
|
|
15
|
+
"version": "10.0.0-alpha.0",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"@types/events": "^3.0.0"
|
|
33
33
|
},
|
|
34
34
|
"type": "module",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "d98a62dea33f5bcd93bc0eda133242da9fe441e3"
|
|
36
36
|
}
|
package/src/CameraUtils.js
CHANGED
|
@@ -52,6 +52,23 @@ export function canvasToBase64(canvas, type = 'image/png', quality = null) {
|
|
|
52
52
|
.substring(('data:' + type + ';base64,').length);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} base64
|
|
57
|
+
* @returns {HTMLCanvasElement}
|
|
58
|
+
*/
|
|
59
|
+
export function base64ToCanvas(base64, type = 'image/png') {
|
|
60
|
+
if (type !== 'image/png') {
|
|
61
|
+
throw new Error('Only image/png is supported');
|
|
62
|
+
}
|
|
63
|
+
const canvas = document.createElement('canvas');
|
|
64
|
+
const image = new Image();
|
|
65
|
+
image.src = 'data:image/png;base64,' + base64;
|
|
66
|
+
canvas.width = image.width;
|
|
67
|
+
canvas.height = image.height;
|
|
68
|
+
canvas.getContext('2d').drawImage(image, 0, 0);
|
|
69
|
+
return canvas;
|
|
70
|
+
}
|
|
71
|
+
|
|
55
72
|
/**
|
|
56
73
|
* Creates a pinhole camera from dimensions and a field of view
|
|
57
74
|
* Distortions are not considered
|