-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-image.html
455 lines (403 loc) · 16.4 KB
/
edit-image.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!DOCTYPE html>
<html>
<head>
<title>Edit Image</title>
<link rel="stylesheet" href="css/global.css" />
<link rel="stylesheet" href="css/scan.css" />
</head>
<body>
<div class="ds-div-scanPageHeader">
<div class="ds-div-title">Edit Image</div>
</div>
<div class="ds-div-scanPageDemo">
<div class="ds-div-scanPage-column ds-div-scanPage-column0">
<div><label for="left">Select Source:</label><select size="1" id="source"></select></div>
<input type="button" value="Scan" class="ds-button-bg-black" style="margin-bottom: 20px;"
onclick="AcquireImage();" />
<input type="button" value="Open a local file" class="ds-button-bg-white" onclick="LoadImages();" />
<div id="editDiv">
<div>
<input class="ds-button-bg-white-thin" onclick="btnCrop_onclick()" type="button" value="Crop" />
<input class="ds-button-bg-white-thin" onclick="btnCut_onclick()" type="button" value="Cut" />
</div>
<div>
<input class="ds-button-bg-white-thin" onclick="btnRotateLeft_onclick()" type="button"
value="Rotate Left" />
<input class="ds-button-bg-white-thin" onclick="btnRotate_onclick()" type="button" value="Rotate" />
<input class="ds-button-bg-white-thin" onclick="btnRotateRight_onclick()" type="button"
value="Rotate Right" />
</div>
<div>
<input class="ds-button-bg-white-thin" onclick="btnFlip_onclick()" type="button" value="Flip" />
<input class="ds-button-bg-white-thin" onclick="btnMirror_onclick()" type="button" value="Mirror" />
<input class="ds-button-bg-white-thin" onclick="btnChangeImageSize_onclick()" type="button"
value="Change Image Size" />
</div>
<div>
<input class="ds-button-bg-white-thin" onclick="btnRemoveSelectedImages_onclick()" type="button"
value="Remove Selected Images" />
<input class="ds-button-bg-white-thin" onclick="btnRemoveAllImages_onclick()" type="button"
value="Remove All Images" />
</div>
<div class="dvs-rotateBox" id="dvsRotateBox"
style="left: 110px; top: -80px; position: relative;display: none;">
<div>
<span>Angle :</span><input id="dvsRotateAngle" type="number" value="45">
</div>
<div style="display: flex;">
<span>Interpolation:</span><select size="1" id="dvsRotateInterpolation">
<option value="1">NearestNeighbor</option>
<option value="2">Bilinear</option>
<option value="3">Bicubic</option>
</select>
</div>
<div>
<label><input type="checkbox" id="dvsKeepSize"><span>Keep size</span></label>
</div>
<div>
<input id="dvsRotateOk" type="button" value=" OK " onclick="btnRotateOK_onclick();">
<input id="dvsRotateCancel" type="button" value="Cancel" onclick="btnRotateCancel_onclick();">
</div>
</div>
<div class="dvs-changeSizeBox" id="dvsChangeSizeBox"
style="left: 150px;top: -40px;position: relative;display: none;">
<div>
<span>New Height :</span>
<div>
<input id="dvsChangeH" type="number" value="2200">
<span>pixel</span>
</div>
</div>
<div style="margin-top: 10px;">
<span>New Width :</span>
<div>
<input id="dvsChangeW" type="number" value="1700">
<span>pixel</span>
</div>
</div>
<div style="display: flex;">
<span>Interpolation:</span>
<select size="1" id="dvsChangeSizeInterpolation">
<option value="1">NearestNeighbor</option>
<option value="2">Bilinear</option>
<option value="3">Bicubic</option>
</select>
</div>
<div>
<input id="dvsChangeSizeOk" type="button" value=" OK " onclick="btnChangeSizeOk_onclick();">
<input id="dvsChangeSizeCancel" type="button" value="Cancel"
onclick="btnChangeSizeCancel_onclick();">
</div>
</div>
</div>
</div>
<div class="ds-div-scanPage-column ds-div-scanPage-column1">
<div id="dwtcontrolContainer" style="width: 100%; height: 100%;"></div>
</div>
</div>
<style>
.ds-div-scanPage-column0>div {
margin: 7px;
}
.ds-div-scanPage-column0 label {
width: 120px;
display: inline-block;
}
#editDiv {
margin: 0px;
}
#editDiv input[type=button] {
margin: 5px 0;
}
.dvs-changeSizeBox,
.dvs-rotateBox {
background-color: #f0f0f0;
border: 2px solid #ce5e04;
box-sizing: border-box;
color: #000;
font-family: OpenSans, Segoe UI, SegoeUI, Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 12px;
font-weight: 700;
padding: 0 15px 15px 15px;
position: absolute;
z-index: 9999
}
.dvs-rotateBox>div {
margin-top: 10px;
}
.dvs-rotateBox>div:first-child input {
box-sizing: border-box;
height: 22px;
margin-left: 5px;
width: 155px
}
.dvs-rotateBox>div:nth-child(2) {
align-items: center;
}
.dvs-rotateBox>div:nth-child(2) select {
box-sizing: border-box;
height: 22px;
margin-left: 5px
}
.dvs-rotateBox div:nth-child(3) {
align-items: center;
display: flex;
height: 22px;
}
.dvs-rotateBox>div:nth-child(3) input {
box-sizing: content-box;
height: 15px;
margin: 0 5px 0 0;
width: 15px
}
.dvs-rotateBox>div:nth-child(4) input {
box-sizing: content-box;
font-size: 12px;
height: 24px;
margin-right: 30px;
width: 60px
}
.dvs-changeSizeBox>div {
margin-top: 10px;
align-items: center;
display: flex;
justify-content: space-between
}
.dvs-changeSizeBox input {
box-sizing: border-box;
height: 22px;
margin-left: 5px;
width: 108px
}
.dvs-changeSizeBox>div:nth-child(3) select {
box-sizing: border-box;
height: 22px;
}
.dvs-changeSizeBox>div:nth-child(4) {
justify-content: space-around;
}
.dvs-changeSizeBox>div:nth-child(4) input {
box-sizing: content-box;
font-size: 12px;
height: 24px;
width: 60px;
}
#dvsRotateBox span,
#dvsChangeSizeBox span {
width: auto;
}
#dvsRotateCancel {
margin-left: 15px !important;
}
.ds-div-download {
bottom: 2px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/dwt@latest/dist/dynamsoft.webtwain.min.js"></script>
<script type="text/javascript">
Dynamsoft.DWT.Containers = [{ ContainerId: 'dwtcontrolContainer', Width: '100%', Height: '100%' }];
Dynamsoft.DWT.ProductKey = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
Dynamsoft.DWT.ResourcesPath = 'https://cdn.jsdelivr.net/npm/dwt@latest/dist';
Dynamsoft.DWT.AutoLoad = true;
var DWTObject, deviceList, _iLeft, _iTop, _iRight, _iBottom;
Dynamsoft.DWT.RegisterEvent("OnWebTwainReady", function () {
DWTObject = Dynamsoft.DWT.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer'
if (DWTObject) {
deviceList = [];
DWTObject.GetDevicesAsync().then(function (devices) {
for (var i = 0; i < devices.length; i++) { // Get how many sources are installed in the system
document.getElementById('source').options.add(new Option(devices[i].displayName, i)); // Add the sources in a drop-down list
deviceList.push(devices[i]);
}
}).catch(function (exp) {
alert(exp.message);
});
DWTObject.Viewer.on("pageAreaSelected", function (index, rect) {
if (rect.length > 0) {
var currentRect = rect[rect.length - 1];
_iLeft = currentRect.x;
_iTop = currentRect.y;
_iRight = currentRect.x + currentRect.width;
_iBottom = currentRect.y + currentRect.height;
}
});
DWTObject.Viewer.on("pageAreaUnselected", function (index) {
_iLeft = 0;
_iTop = 0;
_iRight = 0;
_iBottom = 0;
});
_iLeft = 0;
_iTop = 0;
_iRight = 0;
_iBottom = 0;
}
});
function AcquireImage() {
if (DWTObject) {
var ddlSource = document.getElementById('source');
DWTObject.SelectDeviceAsync(deviceList[ddlSource.selectedIndex]).then(function () {
return DWTObject.AcquireImageAsync({
IfShowUI: false,
IfCloseSourceAfterAcquire: true // Scanner source will be disabled/closed automatically after the scan.
});
}).catch(function (exp) {
console.error(exp);
});
}
}
function LoadImages() {
if (DWTObject) {
// Load images in all supported formats (.bmp, .jpg, .tif, .png, .pdf). OnSuccess or OnFailure will be called after the operation
DWTObject.LoadImageEx("", Dynamsoft.DWT.EnumDWT_ImageType.IT_ALL, function () {
console.log('successful');
}, function (errorCode, errorString) {
alert(errorString);
});
}
}
function btnCrop_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
if (_iLeft != 0 || _iTop != 0 || _iRight != 0 || _iBottom != 0) {
DWTObject.Crop(
DWTObject.CurrentImageIndexInBuffer,
_iLeft, _iTop, _iRight, _iBottom
);
_iLeft = 0;
_iTop = 0;
_iRight = 0;
_iBottom = 0;
return;
} else {
alert("Crop: failed. Please first select the area you'd like to crop.");
}
}
}
function btnCut_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
if (_iLeft != 0 || _iTop != 0 || _iRight != 0 || _iBottom != 0) {
DWTObject.Erase(
DWTObject.CurrentImageIndexInBuffer,
_iLeft, _iTop, _iRight, _iBottom
);
_iLeft = 0;
_iTop = 0;
_iRight = 0;
_iBottom = 0;
return;
} else {
alert("Erase: failed. Please first select the area you'd like to crop.");
}
}
}
function btnRotateLeft_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
DWTObject.RotateLeft(DWTObject.CurrentImageIndexInBuffer);
}
}
function btnRotate_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
btnChangeSizeCancel_onclick();
var dvsRotateBox = document.getElementById('dvsRotateBox');
dvsRotateBox.style.display = "";
}
}
function btnRotateOK_onclick() {
var dvsRotateAngle = document.getElementById("dvsRotateAngle");
var dvsKeepSize = document.getElementById("dvsKeepSize");
var dvsRotateInterpolation = document.getElementById("dvsRotateInterpolation");
DWTObject.RotateEx(
DWTObject.CurrentImageIndexInBuffer,
parseInt(dvsRotateAngle.value),
dvsKeepSize.checked,
parseInt(dvsRotateInterpolation.value)
);
btnRotateCancel_onclick();
}
function btnRotateCancel_onclick() {
var dvsRotateBox = document.getElementById('dvsRotateBox');
dvsRotateBox.style.display = "none";
}
function btnRotateRight_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
DWTObject.RotateRight(DWTObject.CurrentImageIndexInBuffer);
}
}
function btnFlip_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
DWTObject.Flip(DWTObject.CurrentImageIndexInBuffer);
}
}
function btnMirror_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
DWTObject.Mirror(DWTObject.CurrentImageIndexInBuffer);
}
}
function btnChangeImageSize_onclick() {
if (DWTObject) {
if (!checkIfImagesInBuffer()) {
return;
}
btnRotateCancel_onclick();
var dvsChangeSizeBox = document.getElementById('dvsChangeSizeBox');
dvsChangeSizeBox.style.display = "";
}
}
function btnChangeSizeOk_onclick() {
var dvsChangeW = document.getElementById("dvsChangeW");
var dvsChangeH = document.getElementById("dvsChangeH");
var dvsChangeSizeInterpolation = document.getElementById("dvsChangeSizeInterpolation");
DWTObject.ChangeImageSize(
DWTObject.CurrentImageIndexInBuffer,
parseInt(dvsChangeW.value),
parseInt(dvsChangeH.value),
parseInt(dvsChangeSizeInterpolation.value)
);
btnChangeSizeCancel_onclick();
}
function btnChangeSizeCancel_onclick() {
var dvsChangeSizeBox = document.getElementById('dvsChangeSizeBox');
dvsChangeSizeBox.style.display = "none";
}
function btnRemoveSelectedImages_onclick() {
if (DWTObject) {
DWTObject.RemoveImage(DWTObject.CurrentImageIndexInBuffer);
}
}
function btnRemoveAllImages_onclick() {
if (DWTObject) {
DWTObject.RemoveAllImages();
}
}
function checkIfImagesInBuffer() {
if (DWTObject.HowManyImagesInBuffer == 0) {
alert("There is no image in buffer.")
return false;
}
else
return true;
}
</script>
</body>
</html>