veryfi-lens-wasm 2.0.7-beta.2 → 2.0.7-beta.3
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.
|
@@ -210,7 +210,6 @@ export const createBottleCapOverlay = (container, options = {}) => {
|
|
|
210
210
|
|
|
211
211
|
const videoRect = videoElement.getBoundingClientRect();
|
|
212
212
|
const circleDiameter = Math.min(videoRect.width, videoRect.height) * circleRadius;
|
|
213
|
-
const squareSize = circleDiameter * 0.7; // Square inside the circle
|
|
214
213
|
|
|
215
214
|
// Calculate scaling factors between screen and video dimensions
|
|
216
215
|
const scaleX = videoElement.videoWidth / videoRect.width;
|
|
@@ -220,24 +219,25 @@ export const createBottleCapOverlay = (container, options = {}) => {
|
|
|
220
219
|
const centerX = (videoRect.width / 2) * scaleX;
|
|
221
220
|
const centerY = (videoRect.height / 2) * scaleY;
|
|
222
221
|
|
|
223
|
-
// Calculate the
|
|
224
|
-
|
|
222
|
+
// Calculate the circle dimensions in video coordinates
|
|
223
|
+
// Use the same scale factor for width and height to maintain aspect ratio
|
|
224
|
+
const circleDiameterInVideo = circleDiameter * scaleX;
|
|
225
225
|
|
|
226
|
-
// Calculate the top-left corner of the
|
|
227
|
-
const cropX = centerX - (
|
|
228
|
-
const cropY = centerY - (
|
|
226
|
+
// Calculate the top-left corner of the circle in video coordinates
|
|
227
|
+
const cropX = centerX - (circleDiameterInVideo / 2);
|
|
228
|
+
const cropY = centerY - (circleDiameterInVideo / 2);
|
|
229
229
|
|
|
230
|
-
// Set cropImgRef dimensions to match the
|
|
231
|
-
cropImgRef.width =
|
|
232
|
-
cropImgRef.height =
|
|
230
|
+
// Set cropImgRef dimensions to match the circle size - make sure width and height are equal
|
|
231
|
+
cropImgRef.width = circleDiameterInVideo;
|
|
232
|
+
cropImgRef.height = circleDiameterInVideo;
|
|
233
233
|
|
|
234
234
|
// Draw the cropped portion to the cropImgRef canvas
|
|
235
235
|
const ctx = cropImgRef.getContext('2d');
|
|
236
236
|
ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
|
|
237
237
|
ctx.drawImage(
|
|
238
238
|
videoElement,
|
|
239
|
-
cropX, cropY,
|
|
240
|
-
0, 0,
|
|
239
|
+
cropX, cropY, circleDiameterInVideo, circleDiameterInVideo,
|
|
240
|
+
0, 0, circleDiameterInVideo, circleDiameterInVideo
|
|
241
241
|
);
|
|
242
242
|
|
|
243
243
|
// Apply square display styling if the method exists
|
|
@@ -223,29 +223,30 @@ export const createCodeStripsOverlay = (container, options = {}) => {
|
|
|
223
223
|
const centerX = (videoRect.width / 2) * scaleX;
|
|
224
224
|
const centerY = (videoRect.height / 2) * scaleY;
|
|
225
225
|
|
|
226
|
-
//
|
|
227
|
-
const
|
|
226
|
+
// Calculate actual crop dimensions in video coordinates
|
|
227
|
+
const cropWidth = rectWidth_px * scaleX;
|
|
228
|
+
const cropHeight = rectHeight_px * scaleY;
|
|
228
229
|
|
|
229
|
-
// Calculate the top-left corner of the
|
|
230
|
-
const cropX = centerX - (
|
|
231
|
-
const cropY = centerY - (
|
|
230
|
+
// Calculate the top-left corner of the rectangle in video coordinates
|
|
231
|
+
const cropX = centerX - (cropWidth / 2);
|
|
232
|
+
const cropY = centerY - (cropHeight / 2);
|
|
232
233
|
|
|
233
|
-
// Set cropImgRef dimensions to match the
|
|
234
|
-
cropImgRef.width =
|
|
235
|
-
cropImgRef.height =
|
|
234
|
+
// Set cropImgRef dimensions to match the rectangle dimensions
|
|
235
|
+
cropImgRef.width = cropWidth;
|
|
236
|
+
cropImgRef.height = cropHeight;
|
|
236
237
|
|
|
237
238
|
// Draw the cropped portion to the cropImgRef canvas
|
|
238
239
|
const ctx = cropImgRef.getContext('2d');
|
|
239
240
|
ctx.clearRect(0, 0, cropImgRef.width, cropImgRef.height);
|
|
240
241
|
ctx.drawImage(
|
|
241
242
|
videoElement,
|
|
242
|
-
cropX, cropY,
|
|
243
|
-
0, 0,
|
|
243
|
+
cropX, cropY, cropWidth, cropHeight,
|
|
244
|
+
0, 0, cropWidth, cropHeight
|
|
244
245
|
);
|
|
245
246
|
|
|
246
|
-
// Set
|
|
247
|
-
if (typeof cropImgRef.
|
|
248
|
-
cropImgRef.
|
|
247
|
+
// Set rectangle display if the method exists
|
|
248
|
+
if (typeof cropImgRef.setRectangleDisplay === 'function') {
|
|
249
|
+
cropImgRef.setRectangleDisplay();
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
// Convert to base64
|
|
@@ -130,6 +130,40 @@ export const createCroppedImage = (container) => {
|
|
|
130
130
|
cropImgCanvas.style.border = '3px solid #00FA6C';
|
|
131
131
|
cropImgCanvas.style.borderRadius = '10px';
|
|
132
132
|
},
|
|
133
|
-
setSquareDisplay
|
|
133
|
+
setSquareDisplay,
|
|
134
|
+
setRectangleDisplay: () => {
|
|
135
|
+
// Get the natural aspect ratio of the canvas
|
|
136
|
+
const aspectRatio = cropImgCanvas.width / cropImgCanvas.height;
|
|
137
|
+
|
|
138
|
+
// Calculate a reasonable size that fits well on the screen
|
|
139
|
+
const maxWidth = Math.min(500, window.innerWidth * 0.9);
|
|
140
|
+
const maxHeight = window.innerHeight * 0.6;
|
|
141
|
+
|
|
142
|
+
// Determine dimensions while preserving aspect ratio
|
|
143
|
+
let width, height;
|
|
144
|
+
if (aspectRatio > maxWidth / maxHeight) {
|
|
145
|
+
// Width is the limiting factor
|
|
146
|
+
width = maxWidth;
|
|
147
|
+
height = width / aspectRatio;
|
|
148
|
+
} else {
|
|
149
|
+
// Height is the limiting factor
|
|
150
|
+
height = maxHeight;
|
|
151
|
+
width = height * aspectRatio;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Apply styles
|
|
155
|
+
cropImgCanvas.style.width = `${width}px`;
|
|
156
|
+
cropImgCanvas.style.height = `${height}px`;
|
|
157
|
+
cropImgCanvas.style.maxWidth = `${width}px`;
|
|
158
|
+
cropImgCanvas.style.maxHeight = `${height}px`;
|
|
159
|
+
cropImgCanvas.style.position = 'fixed';
|
|
160
|
+
cropImgCanvas.style.top = '50%';
|
|
161
|
+
cropImgCanvas.style.left = '50%';
|
|
162
|
+
cropImgCanvas.style.transform = 'translate(-50%, -50%)';
|
|
163
|
+
cropImgCanvas.style.objectFit = 'contain';
|
|
164
|
+
cropImgCanvas.style.display = 'block';
|
|
165
|
+
cropImgCanvas.style.margin = 'auto';
|
|
166
|
+
cropImgCanvas.style.borderRadius = '5px'; // Slightly rounded corners for the rectangle
|
|
167
|
+
}
|
|
134
168
|
});
|
|
135
169
|
};
|