Skip to content

Commit 4720e98

Browse files
Felix-Dynamsoftfelixindrawan
authored andcommitted
feat: update v1 (#14)
- updated home page - updated template - updated to dcv 2.4.2000 - add image preview and crop image to the recognized text lines - removed redundant MRZ formatter (already in template) - add validation status icons to result from DCP - add comm100 livechat
1 parent c6f89e9 commit 4720e98

File tree

6 files changed

+191
-28
lines changed

6 files changed

+191
-28
lines changed

assets/upload-menu.svg

Lines changed: 14 additions & 0 deletions
Loading

css/index.css

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ img {
6666
text-align: center;
6767
background-color: #323234;
6868
margin: 0 auto;
69-
padding: 2rem;
69+
padding: 1rem 2rem 2rem;
7070
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
7171
}
7272

@@ -113,7 +113,6 @@ img {
113113
}
114114

115115
.home-page .description .start-btn {
116-
width: 180px;
117116
height: 6vh;
118117
min-height: 40px;
119118
max-height: 60px;
@@ -287,6 +286,7 @@ img {
287286
max-height: 200px;
288287
}
289288

289+
.result-container .scanned-image img,
290290
.result-container .scanned-image canvas {
291291
object-fit: contain;
292292
width: 100%;
@@ -527,6 +527,20 @@ img {
527527
}
528528
}
529529

530+
/* LIVE CHAT */
531+
.scanner-container .header .live-chat {
532+
width: 24px;
533+
height: 24px;
534+
cursor: pointer;
535+
display: none;
536+
align-items: center;
537+
cursor: pointer;
538+
}
539+
540+
.scanner-container .header .live-chat:hover {
541+
opacity: 0.8;
542+
}
543+
530544
@media screen and (max-width: 800px) {
531545
html,
532546
body,
@@ -552,6 +566,15 @@ img {
552566
font-size: 20px;
553567
padding: 1.5rem;
554568
}
569+
570+
/* LIVE CHAT CSS */
571+
.live-chat {
572+
display: flex !important;
573+
}
574+
575+
#comm100-float-button-20242b05-3781-4d86-9b7f-fab63ddcdde3-2 {
576+
display: none !important;
577+
}
555578
}
556579

557580
@media screen and (max-width: 800px) and (orientation: landscape) {

index.html

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,54 @@ <h3 style="font-weight: normal">Quick Start Options</h3>
7070
<img class="up" src="./assets/arrow-up.svg" alt="up" />
7171
</div>
7272
<div class="camera-list"></div>
73+
<input type="file" class="upload-image-input" style="display: none" />
74+
<div
75+
class="upload-img-btn"
76+
title="Upload an Image"
77+
onclick="document.querySelector('.upload-image-input').click()"
78+
>
79+
<img class="upload-img-icon" src="./assets/upload-menu.svg" alt="upload-menu" />
80+
</div>
7381
<div class="music-container">
7482
<img class="music" src="./assets/music-selected.svg" alt="music" title="Turn sound off" />
7583
<img class="no-music" src="./assets/music-unselected.svg" alt="no-music" title="Turn sound on" />
7684
</div>
77-
<div class="information-btn">
85+
<div class="live-chat">
86+
<svg
87+
data-v-2a1e9ed8=""
88+
width="24"
89+
height="24"
90+
viewBox="0 0 24 24"
91+
class="live-chat-icon"
92+
onclick="Comm100API.do('livechat.button.click')"
93+
>
94+
<g data-v-2a1e9ed8="" transform="translate(-319 -816.551)">
95+
<g data-v-2a1e9ed8="">
96+
<g data-v-2a1e9ed8="" id="conversation-chat-2">
97+
<path
98+
data-v-2a1e9ed8=""
99+
d="M333.5,817.051h-10a4,4,0,0,0-4,4v5a4,4,0,0,0,4,4h1v4l4.5-4h4.5a4,4,0,0,0,4-4v-5A4,4,0,0,0,333.5,817.051Z"
100+
fill="none"
101+
stroke="#aaa"
102+
stroke-linecap="round"
103+
stroke-linejoin="round"
104+
stroke-width="1"
105+
></path>
106+
<path
107+
data-v-2a1e9ed8=""
108+
d="M330.5,833.051v1.5a2.5,2.5,0,0,0,2.5,2.5h2.5l3,3v-3H340a2.5,2.5,0,0,0,2.5-2.5v-3a2.5,2.5,0,0,0-2.5-2.5h-.5"
109+
fill="none"
110+
stroke="#aaa"
111+
stroke-linecap="round"
112+
stroke-linejoin="round"
113+
stroke-width="1"
114+
></path>
115+
</g>
116+
</g>
117+
</g>
118+
</svg>
119+
</div>
120+
<div class="information-btn" title="More Information">
78121
<svg
79122
xmlns="http://www.w3.org/2000/svg"
80123
class="icon icon-tabler icon-tabler-info-circle"
@@ -138,8 +181,8 @@ <h3 style="font-weight: normal">Quick Start Options</h3>
138181
right: 0;
139182
bottom: 0;
140183
margin: auto;
141-
width: 40%;
142-
height: 40%;
184+
width: 20%;
185+
height: 20%;
143186
fill: #aaa;
144187
animation: 1s linear infinite dce-rotate;
145188
"
@@ -358,5 +401,31 @@ <h3 style="font-weight: normal">Quick Start Options</h3>
358401
></iframe>
359402
</noscript>
360403
<!-- End Google Tag Manager -->
404+
<div style="background-repeat: no-repeat; background-position: 0px 0px; margin: 0; padding: 0px 0px 0px 0px">
405+
<!--Begin Comm100 Live Chat Code-->
406+
<div id="comm100-button-20242b05-3781-4d86-9b7f-fab63ddcdde3"></div>
407+
<script type="text/javascript">
408+
var Comm100API = Comm100API || {};
409+
(function (t) {
410+
function e(e) {
411+
var a = document.createElement("script"),
412+
c = document.getElementsByTagName("script")[0];
413+
(a.type = "text/javascript"), (a.async = !0), (a.src = e + t.site_id), c.parentNode.insertBefore(a, c);
414+
}
415+
(t.chat_buttons = t.chat_buttons || []),
416+
t.chat_buttons.push({
417+
code_plan: "20242b05-3781-4d86-9b7f-fab63ddcdde3",
418+
div_id: "comm100-button-20242b05-3781-4d86-9b7f-fab63ddcdde3",
419+
}),
420+
(t.site_id = 90003305),
421+
(t.main_code_plan = "20242b05-3781-4d86-9b7f-fab63ddcdde3"),
422+
e("https://vue.comm100.com/livechat.ashx?siteId="),
423+
setTimeout(function () {
424+
t.loaded || e("https://standby.comm100vue.com/livechat.ashx?siteId=");
425+
}, 5e3);
426+
})(Comm100API || {});
427+
</script>
428+
<!--End Comm100 Live Chat Code-->
429+
</div>
361430
</body>
362431
</html>

js/const.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const cameraViewContainer = document.querySelector(".camera-view-container");
3131
const cameraListContainer = document.querySelector(".camera-list");
3232
const cameraSelector = document.querySelector(".camera-selector");
3333

34+
const uploadImageInput = document.querySelector(".upload-image-input");
35+
3436
const informationBtn = document.querySelectorAll(".information-btn");
3537
const informationListContainer = document.querySelector(".information-list");
3638

js/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init, pDataLoad } from "./init.js";
1+
import { handleCapturedResult, init, pDataLoad } from "./init.js";
22
import { judgeCurResolution, shouldShowScanModeContainer, showNotification } from "./util.js";
33
import { checkOrientation, getVisibleRegionOfVideo } from "./util.js";
44

@@ -141,6 +141,30 @@ const restartVideo = async () => {
141141
};
142142
scanAgainBtn.addEventListener("click", restartVideo);
143143

144+
uploadImageInput.addEventListener("change", async (event) => {
145+
try {
146+
const file = event.target.files[0];
147+
148+
console.log(event);
149+
150+
if (file) {
151+
// Open the camera after the model and .wasm files have loaded
152+
pInit = pInit || (await init);
153+
await pDataLoad.promise;
154+
155+
event.target.value = "";
156+
157+
// Decode selected image with 'both' template.
158+
const result = await cvRouter.capture(file, SCAN_TEMPLATES.both);
159+
handleCapturedResult(result, file);
160+
}
161+
} catch (ex) {
162+
let errMsg = ex.message || ex;
163+
alert(errMsg);
164+
console.error(errMsg);
165+
}
166+
});
167+
144168
cameraSelector.addEventListener("click", (e) => {
145169
informationListContainer.style.display = "none"; // hide information menu
146170

js/init.js

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ const pDataLoad = createPendingPromise();
77
/** LICENSE ALERT - README
88
* To use the library, you need to first specify a license key using the API "initLicense" as shown below.
99
*/
10-
Dynamsoft.License.LicenseManager.initLicense(
11-
"DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAwLTEwMzAwNjk2NyIsIm1haW5TZXJ2ZXJVUkwiOiJodHRwczovL21sdHMuZHluYW1zb2Z0LmNvbS8iLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMCIsInNlc3Npb25QYXNzd29yZCI6IkVUSHZVNlNPV3F3ZiIsInN0YW5kYnlTZXJ2ZXJVUkwiOiJodHRwczovL3NsdHMuZHluYW1zb2Z0LmNvbS8iLCJjaGVja0NvZGUiOjM5OTMzODU2Nn0="
12-
);
10+
Dynamsoft.License.LicenseManager.initLicense("");
1311
/**
1412
* You can visit https://www.dynamsoft.com/customer/license/trialLicense/?product=mrz&utm_source=samples&package=js to get your own trial license good for 30 days.
1513
* For more information, see https://www.dynamsoft.com/capture-vision/docs/web/programming/javascript/user-guide/mrz-scanner.html#specify-the-license or contact [email protected].
@@ -99,31 +97,43 @@ let init = (async () => {
9997

10098
/* Defines the result receiver for the solution.*/
10199
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
102-
resultReceiver.onCapturedResultReceived = (result) => {
103-
const recognizedResults = result.textLineResultItems;
104-
const parsedResults = result.parsedResultItems;
105-
const originalImage = result.items?.[0]?.imageData;
100+
resultReceiver.onCapturedResultReceived = handleCapturedResult;
106101

107-
if (recognizedResults?.length) {
108-
// Play sound feedback if enabled
109-
isSoundOn ? Dynamsoft.DCE.Feedback.beep() : null;
102+
await cvRouter.addResultReceiver(resultReceiver);
103+
})();
104+
105+
export const handleCapturedResult = (result, uploadedImage = null) => {
106+
console.log(result);
107+
const recognizedResults = result.textLineResultItems;
108+
const parsedResults = result.parsedResultItems;
109+
const originalImage = result.items?.[0]?.imageData;
110+
111+
if (recognizedResults?.length) {
112+
// Play sound feedback if enabled
113+
isSoundOn ? Dynamsoft.DCE.Feedback.beep() : null;
110114

111-
// Display image
112-
scannedImage.textContent = "";
113-
scannedImage.append(originalImage.toCanvas());
115+
parsedResultArea.innerText = "";
114116

115-
const parseSuccess = displayResults(recognizedResults[0]?.text, parsedResults?.[0]);
117+
// Add MRZ Text to Result
118+
const mrzElement = resultToHTMLElement("MRZ String", recognizedResults[0]?.text);
119+
mrzElement.classList.add("code");
120+
parsedResultArea.appendChild(mrzElement);
116121

117-
if (!parseSuccess) {
118-
alert(`Failed to parse the content.`);
119-
parsedResultArea.style.justifyContent = "flex-start";
120-
}
122+
const parseSuccess = displayResults(recognizedResults[0]?.text, parsedResults?.[0]);
121123

122-
dispose();
124+
if (!parseSuccess) {
125+
alert(`Failed to parse the content.`);
126+
parsedResultArea.style.justifyContent = "flex-start";
123127
}
124-
};
125-
await cvRouter.addResultReceiver(resultReceiver);
126-
})();
128+
displayImage(uploadedImage || originalImage);
129+
130+
dispose();
131+
} else if (uploadedImage) {
132+
parsedResultArea.innerText = "No results found";
133+
displayImage(uploadedImage);
134+
dispose();
135+
}
136+
};
127137

128138
const displayResults = (recognizedText, parsedResult) => {
129139
parsedResultArea.innerText = "";
@@ -145,12 +155,33 @@ const displayResults = (recognizedText, parsedResult) => {
145155
return false;
146156
};
147157

158+
function displayImage(image) {
159+
scannedImage.textContent = "";
160+
161+
if (image.type?.startsWith("image/")) {
162+
const img = document.createElement("img");
163+
const imageUrl = URL.createObjectURL(image);
164+
165+
img.src = imageUrl;
166+
img.className = "uploaded-image";
167+
168+
img.onload = () => {
169+
URL.revokeObjectURL(imageUrl);
170+
171+
scannedImage.append(img);
172+
};
173+
} else if (image.toCanvas) {
174+
scannedImage.append(image.toCanvas());
175+
}
176+
}
177+
148178
function dispose() {
149179
resultContainer.style.display = "flex"; // Show result container
150180
cameraListContainer.style.display = "none"; // hide header menu windows
151181
informationListContainer.style.display = "none";
152182
scanModeContainer.style.display = "none"; // hide scan mode buttons
153183

184+
cameraEnhancer.close();
154185
cvRouter.stopCapturing();
155186
cameraView.clearAllInnerDrawingItems();
156187
}

0 commit comments

Comments
 (0)