Skip to content

Commit c937e55

Browse files
committed
fix: show full image when uploading photo
1 parent 33274a2 commit c937e55

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

js/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ uploadImageInput.addEventListener("change", async (event) => {
145145
try {
146146
const file = event.target.files[0];
147147

148+
console.log(event);
149+
148150
if (file) {
149151
// Open the camera after the model and .wasm files have loaded
150152
pInit = pInit || (await init);

js/init.js

Lines changed: 6 additions & 36 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=docs&package=js to get your own trial license good for 30 days.
1513
* Note that if you downloaded this sample from Dynamsoft while logged in, the above license key may already be your own 30-day trial license.
@@ -106,6 +104,7 @@ let init = (async () => {
106104
})();
107105

108106
export const handleCapturedResult = (result, uploadedImage = null) => {
107+
console.log(result);
109108
const recognizedResults = result.textLineResultItems;
110109
const parsedResults = result.parsedResultItems;
111110
const originalImage = result.items?.[0]?.imageData;
@@ -127,7 +126,7 @@ export const handleCapturedResult = (result, uploadedImage = null) => {
127126
alert(`Failed to parse the content.`);
128127
parsedResultArea.style.justifyContent = "flex-start";
129128
}
130-
displayImage(uploadedImage || originalImage, recognizedResults[0].location.points);
129+
displayImage(uploadedImage || originalImage);
131130

132131
dispose();
133132
} else if (uploadedImage) {
@@ -157,7 +156,7 @@ const displayResults = (recognizedText, parsedResult) => {
157156
return false;
158157
};
159158

160-
function displayImage(image, points) {
159+
function displayImage(image) {
161160
scannedImage.textContent = "";
162161

163162
if (image.type?.startsWith("image/")) {
@@ -166,40 +165,11 @@ function displayImage(image, points) {
166165

167166
img.src = imageUrl;
168167
img.className = "uploaded-image";
169-
// Crop image based on points
168+
170169
img.onload = () => {
171170
URL.revokeObjectURL(imageUrl);
172171

173-
if (points) {
174-
const canvas = document.createElement("canvas");
175-
const ctx = canvas.getContext("2d");
176-
177-
const width = points[1].x - points[0].x;
178-
const height = points[2].y - points[1].y;
179-
180-
canvas.width = width;
181-
canvas.height = height;
182-
183-
ctx.drawImage(
184-
img,
185-
points[0].x,
186-
points[0].y,
187-
width,
188-
height, // Source coordinates
189-
0,
190-
0,
191-
width,
192-
height // Destination coordinates
193-
);
194-
195-
const croppedImage = new Image();
196-
croppedImage.src = canvas.toDataURL();
197-
croppedImage.className = "uploaded-image";
198-
199-
scannedImage.append(croppedImage);
200-
} else {
201-
scannedImage.append(img);
202-
}
172+
scannedImage.append(img);
203173
};
204174
} else if (image.toCanvas) {
205175
scannedImage.append(image.toCanvas());

0 commit comments

Comments
 (0)