-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
87 lines (80 loc) · 2.01 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="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Clipic.js</title>
<style>
body,
html {
width: 100%;
height: 100%;
background: #f2f2f2;
padding: 0;
margin: 0;
font-size: 1em;
}
.button {
width: 80%;
background: green;
color: #fff;
padding: 10px;
text-align: center;
margin: 20px auto;
border-radius: 4px;
position: relative;
}
.upload-img {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0;
}
#previewImg {
max-width: 100%;
}
</style>
</head>
<body>
<section>
<img id="previewImg" src="https://avatars1.githubusercontent.com/u/25993112?s=460&v=4" alt="预览" />
<div class="button" role="button">
选择图片 <input type="file" name="file" class="upload-img" accept="image/*" onchange="chooseImg(this)" />
</div>
</section>
<script src="./dist/clipic.js"></script>
<script>
var clipic = new Clipic()
function chooseImg(event) {
var files = event.files || event.dataTransfer.files
var reader = new FileReader()
reader.readAsDataURL(files[0])
reader.onload = e => {
clipic.getImage({
// width: 500,
// height: 400,
ratio: 16 / 9,
src: e.target.result,
// buttonText: ['Cancel', 'Reset', 'Done'],
name: 'test',
encode: 'base64', // 支持 base64、blob、file
type: 'png',
// quality: '0.9', // 导出图片的质量
onDone: function (e) {
document.getElementById('previewImg').src = e
},
onCancel: function () {
console.log('取消裁剪')
}
})
}
event.value = ''
}
</script>
</body>
</html>