Skip to content

Commit e53389b

Browse files
committed
fix #37
1 parent 55ab107 commit e53389b

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/components/Gallery.vue

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,28 @@
5151
<v-card-title class="text-h5 grey lighten-2">
5252
{{ photo.name }}
5353
</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>
5656
<v-progress-circular indeterminate color="grey lighten-5"></v-progress-circular>
5757
</v-layout>
5858
</v-img>
5959
<video v-else-if="photo.type=='mp4'" controls autoplay :src="CBv1+'/photos/'+photo.fileName"/>
6060
<v-card-actions>
6161
<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>
6276
<v-btn
6377
color="primary"
6478
text
@@ -153,6 +167,27 @@ export default {
153167
const currentStatus = this.$store.getters.drawerStatus;
154168
this.$store.commit('toggleDrawer', !currentStatus);
155169
},
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+
}
156191
},
157192
data() {
158193
return {
@@ -163,7 +198,9 @@ export default {
163198
l: null,
164199
photo: null,
165200
gallery_detail: null,
166-
confirmDeleteDlg: null
201+
confirmDeleteDlg: null,
202+
get_pixel_color: false,
203+
pixel_color: ''
167204
};
168205
},
169206
computed: {

src/i18n/locales/it/messages.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@
110110
"control_video_rec_stopped": "Registrazione terminata",
111111
"control_sound_playing": "'Nota in riproduzione'",
112112
"control_photo_gallery": "Galleria",
113+
"gallery_pixel_color": "Colore del pixel",
114+
"gallery_get_pixel_color": "Ricava colore del pixel",
113115
"coderbot_status_offline_1": "In attesa che CoderBot torni online...",
114116
"coderbot_status_offline_2": "CoderBot irraggiungibile",
115117
"coderbot_status_offline_3": "Il coderbot risulta offline, non puoi eseguire il programma.",

0 commit comments

Comments
 (0)