-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.html
162 lines (157 loc) · 5.21 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Vue Croppie by Jofferson Tiquez</title>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<link
rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"
>
<link rel="stylesheet" href="https://unpkg.com/croppie/croppie.css">
<script
src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"
></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"
></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.min.js"></script>
<script src="./dist/vue-croppie.js"></script>
</head>
<body>
<div id="app">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">
<img width="40" src="http://i.imgur.com/Gt1xIqP.png" alt="Vue Croppie"> Vue Croppie
<code>v2.0.1</code>
</a>
<button
class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a target="_blank" class="nav-link" href="https://github.com/jofftiquez/vue-croppie">
GitHub
</a>
</li>
<li class="nav-item active">
<a target="_blank" class="nav-link" href="https://twitter.com/jrtiquez">
@jrtiquez
</a>
</li>
</ul>
</div>
</nav>
<br>
<div class="container">
<div class="row justify-content-md-center">
<div class="col-xs-12 col-md-6">
<vue-croppie
ref="croppieRef"
:enableOrientation="true"
@result="result"
:boundary="{height: 400}"
@update="update"
:croppieInitialized="croppieInitialized">
</vue-croppie>
</div>
<div class="col-xs-12 col-md-6">
<img width="400" :src="cropped" alt="" class="rounded mx-auto d-block img-thumbnail" style="min-height: 400px;">
</div>
</div>
</div>
<div class="row mt-5 mb-5">
<div class="col-xs-12 col-md-12 text-center">
<button class="btn btn-dark" @click="bind()">Bind</button>
<button class="btn btn-dark" @click="rotate(+90)">Rotate Left</button>
<button class="btn btn-dark" @click="rotate(-90)">Rotate Right</button>
<button class="btn btn-dark" @click="crop()">Crop</button>
</div>
</div>
</div>
</div>
<script>
var vm = new Vue({
el: '#app',
mounted () {
// Upon mounting of the component, we accessed the .bind({...})
// function to put an initial image on the canvas.
this.$refs.croppieRef.bind({
url: 'http://i.imgur.com/Fv2YOM6.jpg'
})
setTimeout(() => {
this.crop()
}, 1000)
},
data () {
return {
cropped: null,
images: [
'http://i.imgur.com/fHNtPXX.jpg',
'http://i.imgur.com/ecMUngU.jpg',
'http://i.imgur.com/7oO6zrh.jpg',
'http://i.imgur.com/miVkBH2.jpg',
'http://i.imgur.com/Fv2YOM6.jpg'
]
}
},
methods: {
bind() {
// Randomize cat photos, nothing special here.
let url = this.images[Math.floor(Math.random() * this.images.length)];
// Just like what we did with .bind({...}) on
// the mounted() function above.
this.$refs.croppieRef.bind({
url: url,
});
},
// CALLBACK USAGE
crop() {
// Here we are getting the result via callback function
// and set the result to this.cropped which is being
// used to display the result above.
let options = {
format: 'jpeg'
}
this.$refs.croppieRef.result(options, (output) => {
this.cropped = output;
});
},
// EVENT USAGE
cropViaEvent() {
this.$refs.croppieRef.result(options);
},
result(output) {
this.cropped = output;
},
update(val) {
console.log(val);
},
rotate(rotationAngle) {
// Rotates the image
this.$refs.croppieRef.rotate(rotationAngle);
},
croppieInitialized() {
// This method will be executed when the croppie is initialized
// You can use it to set the image
// this.$refs.croppieRef.bind({
// url: 'http://i.imgur.com/Fv2YOM6.jpg',
// });
console.log('Croppie was initialized');
}
}
})
</script>
</body>
</html>