-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
508 lines (430 loc) · 16.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta charset="utf-8">
<title>ColorSplash</title>
<meta name="color schemes from pictures" content="">
<meta name="Carlton Segbefia" content="">
<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/custom.css">
<!-- Favicon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<link rel="icon" type="image/png" href="images/favicon.png">
</head>
<body>
<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div id="app" class="app">
<div class="intro" ref="intro">
<div class="intro-search">
<h1 class="intro-logo">ColorSplash</h1>
<h5 v-observe-visibility="introSearchVisibilityChanged" class="intro-title">Get Color Schemes from Images</h5>
<input v-model="query" v-on:keyup.enter="search()" class="intro-search-bar" placeholder="enter search" style="padding-left: 1em;">
<button v-on:click="search()" class="intro-search-btn button-primary">Search</button>
<!-- <button v-on:click="search()" class="intro-search-btn button-primary">Upload Image</button> -->
<div class="upload-btn-wrapper">
<button class="intro-search-btn button-primary">Upload Image</button>
<input @change="imageChange($event)" id="imageUpload" type="file" name="imageUpload" accept="image/*" />
</div>
</div>
</div>
<div class="container">
<!-- <div v-if="showNav" class="nav-bar">
<div class="container">
<div class="row ">
<div class="two columns logo nav-bar-item">ColorSplash</div>
<div class="seven columns bar nav-bar-item">
<input v-model="query" class="ten columns search "
placeholder="search or enter url" style="padding-left: 1em;">
<button v-on:click="search()" class="two columns search-btn button-primary">Search</button>
</div>
<div class="three columns nav-bar-item">
<a class="">Random</a>
<a class="" v-on:click="showAbout()">About</a>
</div>
</div>
</div>
</div> -->
<div class="row">
<div v-if="this.galleryState" id="gallery" ref="gallery" class="gallery">
<h2 class="gallery-title">{{this.searchedQuery}}</h2>
<masonry :cols="{default: 3, 1000: 3, 700: 2, 500: 1}" :gutter="0">
<div class="gallery-item" v-for="(item, index) in items" :key="index" v-on:click="showModal(item.urls.small, item.user.name, item.user.links.html)">
<img class="u-max-full-width" :src="item.urls.small" alt="an image from unsplash">
</div>
</masonry>
</div>
</div>
<div class="row">
<button v-if="showButton()" class="more-btn button-primary two columns offset-by-five" v-on:click="loadMore()">Load More</button>
</div>
<div class="row">
<button v-if="showNav" class="button-primary to-top-btn" v-on:click="gotoIntro()">TOP</button>
</div>
</div>
<footer class="footer">
<div class="container">
<div class="twelve columns">
<div class="two columns">
<a class="pointer" style="text-decoration: underline;" v-on:click="showAbout()">About</a>
</div>
<div class="two columns">
<a href="mailto:[email protected]">Contact Me</a>
</div>
<div class="seven columns">
<p>© 2019. Carlton Segbefia. All Rights Reserved.</p>
</div>
</div>
</div>
</footer>
<div class="modal" v-if="modalState">
<div class="container modal-content " v-click-outside="hideModal">
<div class="row">
<img class="modal-image" :src="modalImage" ref="modal-image"/>
<!-- <div class="modal-image" v-bind:style="{ backgroundImage: 'url(' + modalImage + ')' }"> </div> -->
</div>
<div class="row modal-info">
<label v-if="modalName" class="modal-name"> Photo by <a :href="creatorReferral + '?utm_source=clrSplash&utm_medium=referral'">{{creatorName}}</a> on <a href="https://unsplash.com/?utm_source=clrSplash&utm_medium=referral">Unsplash</a></label>
</div>
<div class="row">
<div class="two columns modal-color" v-for="swatch in swatches">
<div class="color-block" v-bind:style="{'background-color': swatch.hex }"> </div>
<div><span style="float: right;">{{arrToStr(swatch.rgb,'')}}</span></div>
<br />
<div><span style="float: right;">{{swatch.hex}}</span></div>
<!-- <br />
<div><span style="float: left;">CMYK:</span><span style="float: right;">{{arrToStr(swatch.cmyk,'')}}</span></div> -->
</div>
</div>
</div>
</div>
<div class="modal" v-if="aboutState">
<div class="container modal-content " v-click-outside="hideAbout">
<div class="row">
<h1>About ColorSplash</h1>
<h2>What is it?</h2>
<p>
ColorSplash uses the <a href="https://github.com/akfish/node-vibrant/">node-vibrant</a> library
to extract colors from images and presents them in a simple and easy to use way.
It gets images from <a href="https://unsplash.com/">Unsplash</a>.
</p>
<h2>Why use it?</h2>
<p>
Deciding on colors for projects is a surprisingly time-consuming project.
ColorSplash aims to serve as a tool to generate beautiful color schemes based on images to speed up the process.
</p>
<h2>Who is this for?</h2>
<p>
Anyone who wants to save time on design projects or wants a color scheme to go with a picture.
</p>
<h2>Who made this?</h2>
<p>
My name is Carlton Segbefia. I’m a computer science and sociology major in Grinnell College with a love for design.
ColorSplash was an idea that came to mind when I was working on a poster for a club event and after a few months of work between colors,
I completed it. Feel free to send any and all feedback to <em> [email protected]</em>.
</p>
<h2>Future Improvements?</h2>
<p>
Currently, ColorSplash uses a direct method of quantizing the images and extracting colors based on the amount of representation.
A better method would be to account for the ways humans perceive colors and how they look when put together.
In other words, rather than focusing on accuracy, rather focus on how the colors look together, This can probably be done with a bit of machine learning.
</p>
</div>
</div>
</div>
</div>
<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<script src="js/vue.min.js"></script>
<script src="js/vibrant.js"></script>
<script src="js/axios.min.js"></script>
<script src="js/vue-masonry.min.js"></script>
<script src="js/vue-observe-visibility.min.js"></script>
<script src="js/vue-scrollto.js"></script>
<script>
Vue.directive('click-outside', {
bind: function(el, binding, vnode) {
el.clickOutsideEvent = function(event) {
// here I check that click was outside the el and his childrens
if (!(el == event.target || el.contains(event.target))) {
// and if it did, call method provided in attribute value
vnode.context[binding.expression](event);
}
};
document.body.addEventListener('click', el.clickOutsideEvent)
},
unbind: function(el) {
document.body.removeEventListener('click', el.clickOutsideEvent)
},
});
VueScrollTo.setDefaults({
container: "body",
duration: 500,
easing: "ease",
offset: 0,
force: true,
cancelable: true,
onStart: false,
onDone: false,
onCancel: false,
x: false,
y: true
});
vm = new Vue({
el: '#app',
components: {
},
data: {
modalState: false,
aboutState: false,
query: '',
galleryState: false,
modalImage: '',
modalName: false,
creatorName:'',
creatorReferral:'',
file: {},
fileLoaded: false,
maxPages: 1,
swatches: [],
varToken: "6706c7e8d2b9ed3f89b647a0201804c88f2846e3f109be44940efcc4a23db74a",
showNav: false,
searchedQuery: "",
page: 1,
items: [],
},
methods: {
onInitialized() {
this.eventLog += 'Initialized\n';
},
// get curated photos from unsplash and assign to items
getCuratedPhotos() {
},
showButton() {
if (this.galleryState) {
if (this.page < this.maxPages) {
return true;
} else {
return false;
}
} else {
return false;
}
},
imageChange(evt) {
this.file = evt.target.files[0];
var vm = this;
this.loadImage(this.file)
},
loadImage(file) {
var reader = new FileReader();
var vm = this;
reader.onload = (e) => {
this.fileLoaded = true;
vm.showModal(e.target.result, "you?");
};
reader.readAsDataURL(file);
},
search() {
if (this.query != '') {
if (this.validURL(this.query)) {
this.showModal(this.query, "Unknown");
} else {
this.galleryState = true;
this.searchedQuery = this.query;
this.loadImages(this.query);
}
}
},
gotoGallery() {
VueScrollTo.scrollTo(this.$refs.gallery)
},
gotoIntro() {
VueScrollTo.scrollTo(this.$refs.intro)
this.showNav = false;
},
loadMore: function() {
// console.log("loadMore");
this.page = this.page + 1
this.addImages(this.searchedQuery, this.page);
},
loadImages(searchQuery) {
// console.log("loadImages");
axios.get('http://api.unsplash.com/search/photos/', {
params: {
page: 1,
query: searchQuery
},
headers: {
Authorization: 'Client-ID ' + this.varToken
}
}).then(response => (this.items = response.data.results,
this.maxPages = response.data.total_pages,
this.gotoGallery()))
},
addImages(searchQuery, page) {
axios.get('http://api.unsplash.com/search/photos/', {
params: {
page: page,
query: searchQuery
},
headers: {
Authorization: 'Client-ID ' + this.varToken
}
}).then(response => (this.items.push(...response.data.results)))
},
validURL(str) {
var regex = /^(f|ht)tps?:\/\//;
if (!regex.test(str)) {
return false;
} else {
return true;
}
},
closeModalWithEsc(e) {
if (e.keyCode === 27 && this.modalState) {
this.modalState = false
}
},
hideModal() {
// console.log("hideModal");
document.documentElement.style.overflow = 'auto';
this.modalState = false;
this.showNav = true;
this.fileLoaded = false;
this.swatches = [];
this.modalName = false;
},
hideAbout() {
// console.log("hideAbout");
document.documentElement.style.overflow = 'auto';
this.aboutState = false;
this.showNav = true;
},
showAbout() {
// console.log("showAbout");
document.documentElement.style.overflow = 'hidden';
this.aboutState = true;
this.showNav = false;
},
introSearchVisibilityChanged(isVisible, entry) {
this.showNav = !isVisible;
},
showModal(imageUrl, creator, referral) {
// console.log("showModal");
document.documentElement.style.overflow = 'hidden';
this.modalImage = imageUrl;
var image = new Image();
image.crossOrigin = "anonymous";
image.onload = function () {
vm.getSwatches(image);
};
image.src = imageUrl ;
// this.getSwatches(imageUrl);
this.modalState = true;
this.showNav = false;
if (this.fileLoaded) {
this.modalName = true;
} else {
this.creatorName = creator;
this.creatorReferral = referral;
if (this.creatorReferral == ''){
this.modalName = false;
}else{
this.modalName = true;
}
}
},
getSwatches(imageUrl) {
var Options = {
colorCount: 256,
quality: 1,
maxDimension: undefined,
filters: [],
ImageClass: Image.Browser,
quantizer: Vibrant.Quantizer.MMCQ,
generator: Vibrant.Generator.Default,
};
var v = new Vibrant(imageUrl, Options);
v.getPalette().then((palette) => this.updatePalette(palette));
// v.getPalette((err, palette) => this.updatePalette(palette));
},
updatePalette(swatches) {
var i = 0;
var rgb = [];
this.swatches = [];
for (var swatch in swatches) {
if (swatches.hasOwnProperty(swatch) && swatches[swatch]) {
// console.log(swatch, swatches[swatch].getHex())
var item = {
hex: '',
rgb: '',
cmyk: ''
};
item.hex = swatches[swatch].getHex();
rgb = swatches[swatch].getRgb();
rgb = rgb.map(this.toInt)
item.rgb = rgb;
item.cmyk = this.rgb2cmyk(rgb);
// item.cmyk = swatches[swatch].getHsl();
this.swatches.push(item);
// this.swatches[i].hex = swatches[swatch].getHex();
// rgb = swatches[swatch].getRgb();
// this.swatches[i].rgb = rgb;
// this.swatches[i].cmyk = this.rgb2cmyk(rgb);
}
}
},
toInt(v){
return Number((v).toFixed(0));
},
arrToStr(arr, endStr) {
var str = '';
str += arr[0] + endStr;
for (i = 1; i < arr.length; i++) {
str += ', ' + arr[i] + endStr;
}
return str;
},
rgb2cmyk(RGB) {
var result = [0, 0, 0, 0];
r = RGB[0] / 255;
g = RGB[1] / 255;
b = RGB[2] / 255;
result[3] = Math.min(1 - r, 1 - g, 1 - b);
result[0] = (1 - r - result[3]) / (1 - result[3]);
result[1] = (1 - g - result[3]) / (1 - result[3]);
result[2] = (1 - b - result[3]) / (1 - result[3]);
result[0] = Math.round(result[0] * 100);
result[1] = Math.round(result[1] * 100);
result[2] = Math.round(result[2] * 100);
result[3] = Math.round(result[3] * 100);
return result;
},
},
created() {
document.addEventListener('keydown', this.closeModalWithEsc)
},
destroyed() {
document.removeEventListener('keydown', this.closeModalWithEsc)
},
events: {
hideModalEvent: function() {
this.hideModal();
}
}
});
</script>
</body>
</html>