-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
196 lines (145 loc) · 7.01 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
<!DOCTYPE html>
<title>osu Receptor</title>
<link rel="stylesheet" href="styles.css">
<script src="jszip.min.js"></script>
<script src="stat_FileSaver.min.js"></script>
<script type="text/javascript">
function previewFiles() {
var preview = document.querySelector('#preview');
var files = document.querySelector('input[type=file]').files;
preview.innerHTML = "";
function readAndPreview(file) {
// Make sure `file.name` matches our extensions criteria
if ( /\.(jpe?g|png)$/i.test(file.name) ) {
var reader = new FileReader();
reader.addEventListener("load", function () {
var image = new Image();
image.title = file.name;
image.src = this.result;
preview.appendChild( image );
var KeyAutoHeight = image.height / (image.width / document.getElementById("ColumnSize").value);
document.getElementById("MaxBottom2").innerHTML = "Useful if using KeyStyle, also this bypass the HitPosition value, therefore if you use receptor the HitPosition is 480, and for Key it is " + (480 - Math.round(KeyAutoHeight));
image.height = 100;
}, false);
reader.readAsDataURL(file);
}
}
if (files) {
[].forEach.call(files, readAndPreview);
}
}
function ConvertReceptor() {
var body = document.querySelector('#Convert');
body.innerHTML = "";
var files = document.querySelector('input[type=file]').files;
var images = [];
var counter = 0;
ReceptorImage = document.getElementById("Receptor");
Columnsize = document.getElementById("ColumnSize").value;
Hitposition = document.getElementById("HitPosition").value;
var ImagePosition = (Hitposition * 1.6) - (Columnsize * 1.6);
var ImageSizeHeight = Columnsize * 1.6;
function readAndDraw(file) {
if ( /\.(jpe?g|png)$/i.test(file.name) ) {
var reader = new FileReader();
reader.addEventListener("load", function () {
var image = new Image();
image.title = file.name;
image.src = this.result;
var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = 768;
if (document.getElementById("KeyStyle").checked) {
ImagePosition = (Hitposition * 1.6);
var KeyAutoHeight = image.height / (image.width / Columnsize);
ImageSizeHeight = KeyAutoHeight * 1.6;
}
if (document.getElementById("MaxBottom").checked) {
ImagePosition = 768 - ImageSizeHeight;
}
var ctx = canvas.getContext("2d");
ctx.drawImage(
image,
0, 0, // beginning of the image we grab
image.width, image.height, // end of the image we grab
0, ImagePosition, // Move the position of the image
image.width, ImageSizeHeight // set the size of the image
);
// Preview the result
// var Result = new Image();
// Result.src = canvas.toDataURL();
// Result.height = 240;
// body.appendChild(Result);
convertImgToBase64URL(canvas.toDataURL(), function (base64Img, url) {
images.push({
url: url,
data: base64Img,
name: file.name
});
counter++;
if (counter == files.length) {
createArchive(images);
}
});
}, false);
reader.readAsDataURL(file);
}
}
if (files) {
[].forEach.call(files, readAndDraw);
}
}
function convertImgToBase64URL(url, callback){
var img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function(){
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'), dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL();
callback(dataURL, url);
canvas = null;
};
img.src = url;
}
function createArchive(images){
var zip = new JSZip();
var img = zip.folder("images");
for (var i=0; i < images.length; i++) {
var commaIdx = images[i].data.indexOf(",");
img.file(images[i].name, images[i].data.slice(commaIdx + 1), {base64: true});
}
zip.generateAsync({type:"blob"}).then(function(file) {
saveAs(file, "images.zip");
})
}
</script>
</head>
<body>
<center>
<input id="browse" type="file" onchange="previewFiles()" multiple="">
<div id="preview"></div>
<div id="columnsize">
<label for="ColumnSize">ColumnSize (1 - 100):</label>
<input type="number" id="ColumnSize" name="ColumnSize" min="1" max="100">
</div>
<div id="hitposition">
<label for="HitPosition">HitPosition (0 - 480):</label>
<input type="number" id="HitPosition" name="HitPosition" min="0" max="480">
</div>
<div id="Keystyle">
<label for="KeyStyle">KeyStyle ? (note stop on top of receptor)</label>
<input type="checkbox" id="KeyStyle" name="KeyStyle">
</div>
<div id="Maxbottom">
<label for="MaxBottom">Want the receptor to automatically be at the max bottom ? (or top if upscroll)</label>
<input type="checkbox" id="MaxBottom" name="MaxBottom">
<br>
<label for="MaxBottom2" id="MaxBottom2" style="font-size: 12px">Useful if using KeyStyle, also this bypass the HitPosition value, therefore if you use receptor the HitPosition is 480, and for Key it is MATH (select image first)</label>
</div>
<button type="button" onclick="ConvertReceptor()">Generate Archives</button>
<div id="Convert"></div>
</center>
</body></html>