51
51
<v-card-title class =" text-h5 grey lighten-2" >
52
52
{{ photo.name }}
53
53
</v-card-title >
54
- <v-img v-if =" photo.type=='jpg'" :src =" CBv1+'/photos/'+photo.fileName" aspect-ratio = " 1 " class =" grey lighten-2" >
55
- <v-layout slot =" placeholder" fill-height align-center justify-center ma-0 >
54
+ <v-img v-if =" photo.type=='jpg'" height = " 100% " :src =" CBv1+'/photos/'+photo.fileName" class =" grey lighten-2" ref = " photo " @click = " getPixelColor " >
55
+ <v-layout slot =" placeholder" align-center justify-center ma-0 >
56
56
<v-progress-circular indeterminate color =" grey lighten-5" ></v-progress-circular >
57
57
</v-layout >
58
58
</v-img >
59
59
<video v-else-if =" photo.type=='mp4'" controls autoplay :src =" CBv1+'/photos/'+photo.fileName" />
60
60
<v-card-actions >
61
61
<v-spacer ></v-spacer >
62
+ <v-text-field v-if =" get_pixel_color" v-model =" pixel_color" v-bind:label =" $t('message.gallery_pixel_color')"
63
+ readonly
64
+ >
65
+ </v-text-field >
66
+ <v-btn-toggle
67
+ v-model =" get_pixel_color"
68
+ >
69
+ <v-btn
70
+ text
71
+ value =" true"
72
+ >
73
+ {{ $t("message.gallery_get_pixel_color") }}
74
+ </v-btn >
75
+ </v-btn-toggle >
62
76
<v-btn
63
77
color =" primary"
64
78
text
@@ -153,6 +167,27 @@ export default {
153
167
const currentStatus = this .$store .getters .drawerStatus ;
154
168
this .$store .commit (' toggleDrawer' , ! currentStatus);
155
169
},
170
+ getPixelColor (event ) {
171
+ if (this .get_pixel_color ) {
172
+ const img = this .$refs .photo .image ;
173
+ const canvas = document .createElement (' canvas' );
174
+ canvas .width = img .width ;
175
+ canvas .height = img .height ;
176
+ img .crossOrigin = ' Anonymous' ;
177
+ canvas .getContext (' 2d' ).drawImage (img, 0 , 0 , img .width , img .height );
178
+ const pixelData = canvas .getContext (' 2d' ).getImageData (event .layerX , event .layerY , 1 , 1 ).data ;
179
+ /* eslint-disable prefer-template */
180
+ const colorHex = ' #' + this .paddedHexString (pixelData[0 ]) + this .paddedHexString (pixelData[1 ]) + this .paddedHexString (pixelData[2 ]);
181
+ /* eslint-enable */
182
+ this .pixel_color = colorHex;
183
+ }
184
+ },
185
+ paddedHexString (n ) {
186
+ const ns = n .toString (16 );
187
+ /* eslint-disable prefer-template */
188
+ return (' 00' + ns).substring (ns .length );
189
+ /* eslint-enable */
190
+ }
156
191
},
157
192
data () {
158
193
return {
@@ -163,7 +198,9 @@ export default {
163
198
l: null ,
164
199
photo: null ,
165
200
gallery_detail: null ,
166
- confirmDeleteDlg: null
201
+ confirmDeleteDlg: null ,
202
+ get_pixel_color: false ,
203
+ pixel_color: ' '
167
204
};
168
205
},
169
206
computed: {
0 commit comments