-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
87 lines (85 loc) · 3.82 KB
/
index.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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title>自动缩图</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css" rel="stylesheet">
<body>
<div class="container">
<div class="card">
<div class="card-header p-2 bg-info">
<input id="file" type="file" />
</div>
<div class="card-img p-3">
<div class="input-group mb-3" style="max-width:450px;">
<div class="input-group-prepend">
<label class="input-group-text">缩图模式</label>
</div>
<select class="custom-select" id="mode"><option>按宽度</option><option>按比例</option><option>按大小(相对于原精度)</option></select>
<div>
<select class="custom-select rounded-0" id="mode_0"><option value="800">800px</option><option value="600" selected>600px</option><option value="400">400px</option></select>
<select class="custom-select rounded-0 d-none" id="mode_1"><option value="1">原大</option><option value="0.5" selected>1/2</option><option value="0.25">1/4</option><option value="0.125">1/8</option></select>
<select class="custom-select rounded-0 d-none" id="mode_2"><option value="100">100KB</option><option value="200" selected>200KB</option><option value="500">500KB</option></select>
</div>
<div class="input-group-append">
<select class="custom-select rounded-0" id="format"><option>JPG-10</option><option selected>JPG-8</option><option>JPG-6</option><option>PNG(无压缩)</option></select>
</div>
</div>
<textarea class="custom-select w-100 d-none" id="img_data"></textarea>
<div class="row mx-auto my-3 text-center" style="overflow-x:auto;">
<img id="showImg" src="" />
</div>
</div>
</div>
</div>
</body>
<script type="application/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="application/javascript" src="jquery.resizeImg.js"></script>
<script type="application/javascript" src="mobileBUGFix.mini.js"></script>
<script type="application/javascript">
$("#file").resizeImg(function(){
let type, quality;
switch ($("#format").get(0).selectedIndex) {
case 0:
type = "image/jpeg";
quality = 1;
break;
case 1:
type = "image/jpeg";
quality = 0.8;
break;
case 2:
type = "image/jpeg";
quality = 0.6;
break;
case 3:
type = "image/png";
quality = 1;
break;
default:
type = "image/jpeg";
quality = 0.8;
}
return {
use_reader: false,
mode: $("#mode").get(0).selectedIndex,
val: $("#mode_"+$("#mode").get(0).selectedIndex).val(),
type: type,
quality: quality,
callback: function(result) {
$("#showImg").attr('src', result);
$("#img_data").removeClass("d-none").val(result.substr(result.indexOf(',') + 1 )).css("height",100);
console.log($("#img_data").val().length);
}
};
});
$("select").change(function() {
$("#file").trigger("change");
});
$("#mode").change(function(){
$(this).next().find("select").addClass("d-none");
$("#mode_"+this.selectedIndex).removeClass("d-none");
});
</script>
</html>