@plusscommunities/pluss-core-app 1.7.0 → 1.7.1
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/dist/module/actions/MediaActions.js +10 -1
- package/dist/module/actions/MediaActions.js.map +1 -1
- package/dist/module/actions/types.js +1 -0
- package/dist/module/actions/types.js.map +1 -1
- package/dist/module/apis/index.js +1 -0
- package/dist/module/apis/index.js.map +1 -1
- package/dist/module/apis/stringActions.js +30 -0
- package/dist/module/apis/stringActions.js.map +1 -0
- package/dist/module/components/AutoOffsetImage.js +173 -0
- package/dist/module/components/AutoOffsetImage.js.map +1 -0
- package/dist/module/components/index.js +1 -0
- package/dist/module/components/index.js.map +1 -1
- package/dist/module/helper.js +25 -2
- package/dist/module/helper.js.map +1 -1
- package/dist/module/js/images/detectFaces.js +28 -0
- package/dist/module/js/images/detectFaces.js.map +1 -0
- package/dist/module/js/images/findLandmarkRange.js +113 -0
- package/dist/module/js/images/findLandmarkRange.js.map +1 -0
- package/dist/module/js/images/getScaledOffset.js +81 -0
- package/dist/module/js/images/getScaledOffset.js.map +1 -0
- package/package.json +18 -17
- package/src/actions/MediaActions.js +8 -1
- package/src/actions/types.js +1 -0
- package/src/apis/index.js +1 -0
- package/src/apis/stringActions.js +28 -0
- package/src/components/AutoOffsetImage.js +177 -0
- package/src/components/index.js +1 -0
- package/src/helper.js +24 -0
- package/src/js/images/detectFaces.js +30 -0
- package/src/js/images/findLandmarkRange.js +105 -0
- package/src/js/images/getScaledOffset.js +83 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import moment from 'moment';
|
|
3
|
+
import { stringActions } from '../../apis';
|
|
4
|
+
import detectFaces from './detectFaces';
|
|
5
|
+
import getScaledOffset from './getScaledOffset';
|
|
6
|
+
|
|
7
|
+
const findLandmarkRange = async (url, options) => {
|
|
8
|
+
let cachedValues;
|
|
9
|
+
if (options && options.cachedValues) {
|
|
10
|
+
cachedValues = options.cachedValues;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const response = await stringActions.getString('plussSpace', `imagefaces_${encodeURIComponent(url)}`);
|
|
14
|
+
cachedValues = response.data;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
console.log('errored from cache');
|
|
17
|
+
}
|
|
18
|
+
if (
|
|
19
|
+
!cachedValues ||
|
|
20
|
+
!cachedValues.faces ||
|
|
21
|
+
!cachedValues.image ||
|
|
22
|
+
(_.isEmpty(cachedValues.faces) &&
|
|
23
|
+
moment()
|
|
24
|
+
.add(-1, 'w')
|
|
25
|
+
.valueOf() > moment(cachedValues.timestamp).valueOf())
|
|
26
|
+
) {
|
|
27
|
+
cachedValues = await detectFaces(url);
|
|
28
|
+
}
|
|
29
|
+
const { faces, image } = cachedValues;
|
|
30
|
+
|
|
31
|
+
let landmarkStartX = null;
|
|
32
|
+
let landmarkStartY = null;
|
|
33
|
+
let landmarkEndX = null;
|
|
34
|
+
let landmarkEndY = null;
|
|
35
|
+
|
|
36
|
+
if (_.isEmpty(faces)) {
|
|
37
|
+
landmarkStartX = image.width / 2;
|
|
38
|
+
landmarkStartY = image.height / 2;
|
|
39
|
+
landmarkEndX = image.width / 2;
|
|
40
|
+
landmarkEndY = image.height / 2;
|
|
41
|
+
} else {
|
|
42
|
+
faces.forEach(face => {
|
|
43
|
+
const { bounds } = face;
|
|
44
|
+
|
|
45
|
+
if (!landmarkStartX || bounds.origin.x < landmarkStartX) {
|
|
46
|
+
landmarkStartX = bounds.origin.x;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!landmarkStartY || bounds.origin.y < landmarkStartY) {
|
|
50
|
+
landmarkStartY = bounds.origin.y;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const faceEndX = bounds.origin.x + bounds.size.width;
|
|
54
|
+
if (!landmarkEndX || faceEndX > landmarkEndX) {
|
|
55
|
+
landmarkEndX = faceEndX;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const faceEndY = bounds.origin.y + bounds.size.height;
|
|
59
|
+
if (!landmarkEndY || faceEndX > landmarkEndY) {
|
|
60
|
+
landmarkEndY = faceEndY;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let targetWidth = image.width;
|
|
66
|
+
let targetHeight = image.height;
|
|
67
|
+
|
|
68
|
+
if (options && options.targetWidth && options.targetHeight) {
|
|
69
|
+
const { scaleFactor } = getScaledOffset(image.width, image.height, options.targetWidth, options.targetHeight);
|
|
70
|
+
landmarkStartX *= scaleFactor;
|
|
71
|
+
landmarkStartY *= scaleFactor;
|
|
72
|
+
landmarkEndX *= scaleFactor;
|
|
73
|
+
landmarkEndY *= scaleFactor;
|
|
74
|
+
targetWidth = options.targetWidth;
|
|
75
|
+
targetHeight = options.targetHeight;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (landmarkStartX < 0) {
|
|
79
|
+
landmarkStartX = 0;
|
|
80
|
+
}
|
|
81
|
+
if (landmarkStartY < 0) {
|
|
82
|
+
landmarkStartY = 0;
|
|
83
|
+
}
|
|
84
|
+
if (landmarkEndX > targetWidth) {
|
|
85
|
+
landmarkEndX = targetWidth;
|
|
86
|
+
}
|
|
87
|
+
if (landmarkEndY > targetHeight) {
|
|
88
|
+
landmarkEndY = targetHeight;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
start: {
|
|
93
|
+
x: landmarkStartX,
|
|
94
|
+
y: landmarkStartY,
|
|
95
|
+
},
|
|
96
|
+
end: {
|
|
97
|
+
x: landmarkEndX,
|
|
98
|
+
y: landmarkEndY,
|
|
99
|
+
},
|
|
100
|
+
height: image.height,
|
|
101
|
+
width: image.width,
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export default findLandmarkRange;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const getScaledOffset = (sourceWidth, sourceHeight, targetWidth, targetHeight) => {
|
|
2
|
+
const sourceRatio = sourceWidth / sourceHeight;
|
|
3
|
+
const targetRatio = targetWidth / targetHeight;
|
|
4
|
+
|
|
5
|
+
// same ratio. no adjustment needed.
|
|
6
|
+
if (sourceRatio === targetRatio) {
|
|
7
|
+
return {
|
|
8
|
+
width: targetWidth,
|
|
9
|
+
height: targetHeight,
|
|
10
|
+
scaleFactor: targetWidth / sourceWidth,
|
|
11
|
+
offset: {
|
|
12
|
+
x: 0,
|
|
13
|
+
y: 0,
|
|
14
|
+
},
|
|
15
|
+
bounds: {
|
|
16
|
+
start: {
|
|
17
|
+
x: 0,
|
|
18
|
+
y: 0,
|
|
19
|
+
},
|
|
20
|
+
end: {
|
|
21
|
+
x: targetWidth,
|
|
22
|
+
y: targetHeight,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// source is higher than target. height scaling and y offset required.
|
|
29
|
+
if (sourceRatio < targetRatio) {
|
|
30
|
+
const scaleFactor = targetWidth / sourceWidth;
|
|
31
|
+
const adjustedHeight = sourceHeight * scaleFactor;
|
|
32
|
+
const yOffset = (adjustedHeight - targetHeight) / 2;
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
width: targetWidth,
|
|
36
|
+
height: adjustedHeight,
|
|
37
|
+
scaleFactor,
|
|
38
|
+
offset: {
|
|
39
|
+
x: 0,
|
|
40
|
+
y: -yOffset,
|
|
41
|
+
},
|
|
42
|
+
bounds: {
|
|
43
|
+
start: {
|
|
44
|
+
x: 0,
|
|
45
|
+
y: yOffset,
|
|
46
|
+
},
|
|
47
|
+
end: {
|
|
48
|
+
x: targetWidth,
|
|
49
|
+
y: yOffset + adjustedHeight,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// source is wider than target. width scaling and x offset required.
|
|
56
|
+
if (sourceRatio > targetRatio) {
|
|
57
|
+
const scaleFactor = targetHeight / sourceHeight;
|
|
58
|
+
const adjustedWidth = sourceWidth * scaleFactor;
|
|
59
|
+
const xOffset = (adjustedWidth - targetWidth) / 2;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
width: adjustedWidth,
|
|
63
|
+
height: targetHeight,
|
|
64
|
+
scaleFactor,
|
|
65
|
+
offset: {
|
|
66
|
+
x: -xOffset,
|
|
67
|
+
y: 0,
|
|
68
|
+
},
|
|
69
|
+
bounds: {
|
|
70
|
+
start: {
|
|
71
|
+
x: xOffset,
|
|
72
|
+
y: 0,
|
|
73
|
+
},
|
|
74
|
+
end: {
|
|
75
|
+
x: xOffset + adjustedWidth,
|
|
76
|
+
y: targetHeight,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default getScaledOffset;
|