/
default-transforms-example.vue
165 lines (157 loc) · 3.38 KB
/
default-transforms-example.vue
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
<script>
import { Cropper } from 'vue-advanced-cropper';
import ExampleWrapper from './Components/ExampleWrapper';
import { saveAs } from 'file-saver';
export default {
components: {
Cropper,
ExampleWrapper,
},
data() {
return {
image: require('../assets/pictures/pexels-photo-5006465.jpeg'),
transform: 'horizontal-flip',
};
},
computed: {
defaultTransforms() {
if (this.transform === 'horizontal-flip') {
return {
flip: {
horizontal: true,
},
};
} else if (this.transform === 'vertical-flip') {
return {
flip: {
vertical: true,
},
};
} else if (this.transform === 'rotate-90') {
return {
rotate: 90,
};
} else if (this.transform === 'rotate-180') {
return {
rotate: 180,
};
}
},
},
methods: {
loadImage(event) {
const { files } = event.target;
if (files && files[0]) {
if (this.image.src) {
URL.revokeObjectURL(this.image.src);
}
this.image = URL.createObjectURL(files[0]);
}
},
},
destroyed() {
// Revoke the object URL, to allow the garbage collector to destroy the uploaded before file
if (this.image) {
URL.revokeObjectURL(this.image);
}
},
};
</script>
<template>
<example-wrapper
:no-border="true"
class="default-transforms-example"
href="https://github.com/advanced-cropper/vue-advanced-cropper/blob/master/example/docs/.vuepress/components/default-transforms-example.vue"
>
<div class="default-transforms-example__cropper-wrapper">
<cropper class="default-transforms-example__cropper" :default-transforms="defaultTransforms" :src="image" />
</div>
<div class="panel">
<div class="panel__left">
<div class="input">
<span class="input__label">Default Transforms</span>
<select v-model="transform" class="input__control" type="text">
<option value="horizontal-flip">Horizontal Flip</option>
<option value="vertical-flip">Vertical Flip</option>
<option value="rotate-90">Rotate 90°</option>
<option value="rotate-180">Rotate 180°</option>
</select>
</div>
</div>
<div class="panel__right">
<button class="button" @click="$refs.file.click()">
Upload image
<input ref="file" type="file" accept="image/*" @change="loadImage($event)" />
</button>
</div>
</div>
</example-wrapper>
</template>
<style lang="scss">
.default-transforms-example {
margin-top: 20px;
margin-bottom: 20px;
user-select: none;
&__cropper {
border: solid 1px #eee;
min-height: 300px;
max-height: 500px;
width: 100%;
}
&__cropper-wrapper {
position: relative;
}
&__buttons-wrapper {
display: flex;
justify-content: center;
margin-top: 17px;
}
.input {
&__control {
padding: 8px;
width: 100%;
border: none;
color: black;
font: inherit;
font-size: 15px;
}
&__label {
display: block;
font-size: 11px;
margin-bottom: 5px;
}
}
.button {
width: 160px;
margin-top: 15px;
display: block;
color: white;
font-size: 16px;
padding: 10px 20px;
text-align: center;
background: #1f8255;
cursor: pointer;
transition: background 0.5s;
font-weight: normal;
border: none;
&:hover {
background: #26a069;
text-decoration: none !important;
}
input {
display: none;
}
}
.panel {
color: white;
display: flex;
align-items: flex-end;
padding: 20px;
background: #3fb37f;
&__left {
width: 100%;
padding-right: 30px;
}
}
}
</style>