-
Notifications
You must be signed in to change notification settings - Fork 0
/
Photos.html
146 lines (144 loc) · 3.94 KB
/
Photos.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
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@700&display=swap" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.3/vue.min.js"></script>
<script src=".files.js"></script>
<style>
@page {
size: A4;
margin: 1cm;
}
html, body {
width: 210mm;
max-width: 210mm;
margin: 1cm;
font-family: 'Open Sans', sans-serif;
text-transform: uppercase;
}
.table {
display: table;
border-collapse: collapse;
}
.table:not(first-child) {
margin-top: 2cm;
}
.table:not(last-child) {
page-break-before: always;
}
.row {
display: table-row;
}
.wrapper {
width: 5cm;
height: 5cm;
padding: 3mm;
display: table-cell;
border: 1px dashed black;
color: #69BD45;
}
.photo {
margin-left: auto;
margin-right: auto;
height: 5cm;
width: 5cm;
display:flex;
justify-content:center;
align-items:center;
}
.photo img {
object-fit: contain;
height: 95%;
width: 95%;
}
.name {
padding-top: 3mm;
font-size: 25px;
text-align: center;
}
.print {
display: inline-block;
font-size: 50px;
padding-bottom: 40px;
}
@media print {
.print {
display: none;
}
}
@media screen {
body {
overflow: hidden;
}
.table {
opacity: 0;
}
}
</style>
</head>
<body>
<div id="app">
<template v-if="!photos.length">
<h2>No photos were detected!</h2>
<p>Add some photos to the "Photos" folder, with the filenames being their preferred names, and then open (run) the "Create Photo Cards" file (script) again.</p>
</template>
<template v-else>
<a href="#" @click="print" class="print">Print</a>
<div v-for="(x,table) in tables" class="table" role="table">
<div v-for="(y,row) in rowsPerPage" class="row" role="row">
<div v-for="photo in getPhotos(table, row)" role="cell" class="wrapper">
<div class="photo">
<img :src="`Photos/${photo}`"/>
</div>
<div class="name" ref="name">
<span>{{ photo.replace(/^([^\.\-\_\s\d]+).+/, '$1') }}</span>
</div>
</div>
</div>
</div>
</template>
</div>
<script>
new Vue({
el: '#app',
data() {
return {
photos: [],
photosPerRow: 3,
rowsPerPage: 4,
};
},
mounted() {
this.photos = files
.trim()
.split(/\r?\n/)
.filter(
file => (/\.(gif|jpe?g|tiff?|png|webp|bmp)$/i).test(file)
);
this.$nextTick(this.print);
},
computed: {
rows() {
return Math.ceil(this.photos.length / this.rowsPerPage);
},
tables() {
return Math.ceil(this.rows / this.photosPerRow);
},
},
methods: {
getPhotos(table, row) {
let startIndex = (table * this.photosPerRow * this.rowsPerPage) + (row * this.photosPerRow);
let endIndex = startIndex + this.photosPerRow;
return this.photos.slice(startIndex, endIndex);
},
print() {
if (this.photos.length) {
window.print();
}
},
}
});
</script>
</body>
</html>