-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
523 lines (456 loc) · 19.4 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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<!doctype html>
<html lang="en-us">
<!-- manifest="cache.mf" -->
<head>
<meta name="Description" content="A webassembly version of imagemagick that can crop comics into webtoon or tapas format.">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#ffad04">
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="favicon.png">
<meta name="mobile-web-app-capable" content="yes">
<!-- iphone section -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" href="iphone/touch-icon-iphone.png">
<link rel="apple-touch-icon" sizes="152x152" href="iphone/touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="180x180" href="iphone/touch-icon-iphone-retina.png">
<link rel="apple-touch-icon" sizes="167x167" href="iphone/touch-icon-ipad-retina.png">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_640.png" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_750.png" media="(device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_1242.png" media="(device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_1125.png" media="(device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_1536.png" media="(min-device-width: 768px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_1668.png" media="(min-device-width: 834px) and (max-device-width: 834px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)">
<link rel="apple-touch-startup-image" href="iphone/apple_splash_2048.png" media="(min-device-width: 1024px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: portrait)">
<title>Croppy</title>
<style>
.all-items {
display: flex;
flex-wrap: wrap;
flex-direction: row;
}
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#container {
display: flex;
flex-direction: column;
/*
min-height:100%;
position:relative; */
}
#body {
padding-bottom: 30px;
/* Height of the footer */
}
#footer {
justify-content: flex-end;
/*
position:absolute;
bottom:0;
width:100%;
height:30px; */
}
.image-holder {
flex-direction: column;
page-break-before: always;
width: 700px;
}
.split-image {
float: left;
/* border-left: 1px solid transparent; */
/* border-right: 1px solid transparent; */
}
.split-image:hover {
float: left;
/* border: 1px dashed black; */
outline: 3px dashed blue;
outline-offset: -3px;
}
</style>
<!-- redirect for old browsers -->
<script nomodule type="application/javascript">window.location = "old.html"</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-123529756-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-123529756-1');
</script>
<script type="text/javascript">
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//stat.croppy.duckdns.org/";
_paq.push(['setTrackerUrl', u+'findphp']);
_paq.push(['setSiteId', '3']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'findjs'; s.parentNode.insertBefore(g,s);
})();
</script>
<script DEFER src="https://cdn.jsdelivr.net/g/filesaver.js"></script>
<script DEFER src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
</head>
<body>
<div>
<h3>
<a href="instructions.html">Instructions / Troubleshooting</a>
</h3>
</div>
<div id="body">
<div id="container">
<div class="all-items">
<div id="picture">
<img id='croppy_logo' src="images/Croppy_ver3.small.png" alt="Croppy Logo" title="Logo pic by Laht - https://laht.carrd.co">
<script defer>
// if december or the earliest thanksgiving (Nov 22nd)
// use xmas croppy
const now = new Date()
if( now.getMonth() == 11 || (now.getMonth() == 10 && now.getDate() >= 22)){
document.getElementById('croppy_logo').src = 'images/Croppy_xmas_1.jpg'
}else{
// document.getElementById('croppy_logo').src = 'images/Croppy_ver3.small.png'
}
</script>
</div>
<div>
<!-- If I am sick / don't work you can go to the old croppy at <a href="https://old-croppy.beta1042.duckdns.org">old-croppy</a>, but in general I should be faster, and work on larger images!<br> -->
I take
<b>PNG, PSD, TIFF</b> (best options) or JPG.
<br> You can upload multiple files at once.
<P>
<table>
<tr>
<th>Websites</th>
<th>format ( select all that apply)</th>
</tr>
<tr>
<td>
<label for="DoLine">Line Webtoon</label>
</td>
<td>
<input type="checkbox" name="DoLine" id="DoLine" value="1" checked="checked">
</td>
</tr>
<tr>
<td>
<label for="DoTapas">Tapas</label>
</td>
<td>
<input type="checkbox" name="" id="DoTapas" value="1" />
</td>
</tr>
</table>
<p>
<input type=file name=file id="your-files" aria-label="File Input" accept=".jpg,.jpeg,.png,.bmp,.tif,.tiff,.psd" multiple>
</p>
<br>
<p>Checkout my friend's comic "<a href="https://www.webtoons.com/en/challenge/please-dont-eat-me/1-the-roommate/viewer?title_no=555912&episode_no=2">Please Don't Eat Me</a>", who is trying to unlock ad revenue.</p>
<a href="https://www.webtoons.com/en/challenge/please-dont-eat-me/1-the-roommate/viewer?title_no=555912&episode_no=2"> <img id='promo_logo' height="30%" src="promo-bottom.png" alt="Title cover image for comic Please Don't Eat Me" title="Please Don't Eat Me"></a>
<p>Check this box if you want to add a shout out for this comic at the end of your webtoon update <input type="checkbox" name="AddPromo" id="AddPromo" value="1"/>
</p>
<!-- <table cellpadding="0" cellspacing="0" border="0" style="padding: 0.5vw; vertical-align: text-top; border: none; max-width:100%; max-height:10%; background: transparent;">
<tr style="padding: 0.5vw; border: none; max-width:100%; max-height:10%; background: transparent;">
<td style="padding: 0.5vw; border: none; max-width:100%; max-height:10%; background: transparent; vertical-align: text-top;">
</td>
<td style="padding: 0.5vw; border: none; max-width:100%; max-height:10%; background: transparent;">
<img id='promo_logo' src="promo-side.png" alt="Title cover image for comic Please Don't Eat Me" title="Please Don't Eat Me">
</td>
</tr>
</table> -->
</div>
<div>
</div>
</div>
<div id="Processing" hidden="true">
<H2>Splitting pictures, ignore unresponsive webpage and wait up to 60 seconds per file, then give up.</H2>
</div>
<div style="clear: both"></div>
<div id="imageHolder" class="image-holder"></div>
</div>
</div>
<script type='module'>
//import the library to talk to imagemagick
import * as Magick from 'https://knicknic.github.io/wasm-imagemagick/magickApi.js';
let processing = document.getElementById("Processing");
let imageHolder = document.getElementById('imageHolder');
let doLine = document.getElementById("DoLine");
let doTapas = document.getElementById("DoTapas");
let addPromo = document.getElementById("AddPromo");
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('sw.js', {
updateViaCache: 'none',
// https://developers.google.com/web/updates/2018/06/fresher-sw
}).then(function (registration) {
let refreshing;
navigator.serviceWorker.addEventListener('controllerchange',
function () {
if (refreshing) return;
refreshing = true;
window.location.reload();
}
);
if (registration.active) {
registration.active.addEventListener('message', function (msg) {
alert(msg);
location.reload();
});
}
}, function (err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
function GenerateZipItemName(name, prefix){
if(!doLine.checked || !doTapas.checked)
{
return name;
}
return prefix + '/'+name;
}
async function GetPromoImage(){
var xhr = new XMLHttpRequest();
let data = await new Promise(function(resolve, reject) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status >= 300) {
reject("Error, status code = " + xhr.status)
} else {
resolve(xhr.response);
}
}
}
xhr.open('get', './promo-img.png', true)
xhr.responseType = "blob";
xhr.send();
});
DoSomeTrack("added_promo", "lizz", "lizz");
let arrayBuff = await data.arrayBuffer()
return {
name: 'zzzzzadd-promo-9999.png',
buffer: new Uint8Array(arrayBuff),
blob: data,
}
}
function GenerateZip(line, tapas) {
let zip = new JSZip();
if((line.length + tapas.length ) >0){
for(let item of line){
zip.file(GenerateZipItemName(item.name, 'webtoon'), item.blob);
}
for(let item of tapas){
zip.file(GenerateZipItemName(item.name, 'tapas'), item.blob)
}
zip.generateAsync({ type: "blob" })
.then(function (content) {
// see FileSaver.js
saveAs(content, "split.zip");
});
}
};
// helper to read user inputed files
function ReadFile(file){
let readFile = Magick.CreatePromiseEvent();
// read fileName & content
let fr = new FileReader();
fr.onload = function (txt) {
let fileName = file.name
let encoded_txt = txt.target.result;
let content = new Uint8Array(encoded_txt);
let sourceFilename = fileName
readFile['resolve']([sourceFilename, content]);
}
fr.readAsArrayBuffer(file);
return readFile;
};
let SetProcessing = function (isProcessing){
//filesRemaining.hidden = !isProcessing;
processing.hidden = !isProcessing;
}
function DoSomeTrack(category, action, name){
try{
_paq.push(['trackEvent', category, action, name]);
}catch(e){}
try{
console.log('about to send GA');
gtag('event', action, {
'event_category': category,
'event_label': name,
});
console.log('sent to GA');
}catch(e){console.log(e)}
}
function IsTooLarge(files){
let total = 0
for (let fileIndex = 0; fileIndex < files.length; ++fileIndex){
total = total + files[fileIndex].blob.size
}
// is total greater than 19.5MB
return total > 20459520
}
function CompletedImage(category, action, name){
DoSomeTrack(category, action, name);
try{
_paq.push(['trackGoal', 1]);
}catch(e){}
}
var magickWorker = new Worker('magick.js');
function AlertIt(confirmText, destination) {
var answer = confirm (confirmText)
if (answer)
window.location=destination;
}
function IsJpeg(extension){
extension = extension.toLowerCase()
return extension == "jpeg" || extension == "jpg"
}
// handle new images to process
var control = document.getElementById("your-files");
var processFiles = async function () {
// When the control has changed, there are new files
let files = control.files,
len = files.length;
//if images
if (len > 0) {
//clean up old images and show processing screen
SetProcessing(true);
imageHolder.innerHTML = '';
// for each file requested split them (files isn't an array)
let processedImagesLine=[];
let processedImagesTapas=[];
let failedProcessing = false;
let firstFileName = files[0].name;
let extension_first_file = firstFileName.substring(1+firstFileName.lastIndexOf('.'))
let conversion_destination = ''
if (doLine.checked) {
conversion_destination = 'Line'
}
if (doTapas.checked) {
conversion_destination = 'Tapas'
}
if (doTapas.checked && doTapas.checked) {
conversion_destination = 'Line_Tapas'
}
DoSomeTrack("convert_start", extension_first_file, conversion_destination);
for(let webtoonRetryLogic = 0; webtoonRetryLogic < 3; ++webtoonRetryLogic){
let oldLineSplitCount = processedImagesLine.length
processedImagesLine=[];
processedImagesTapas=[];
for (let fileIndex = 0; fileIndex < files.length; ++fileIndex) {
try{
if (doLine.checked) {
let [fileName,content] = await ReadFile(files[fileIndex]);
let fileNameNoExt = fileName.substring(0, fileName.lastIndexOf('.'));
let splitFiles = []
if(webtoonRetryLogic == 0 && IsJpeg(extension_first_file)){
webtoonRetryLogic =1; //skip attempting to do png
}
let destFilename = fileNameNoExt + '-%d.png'
// first do PNG
switch (webtoonRetryLogic){
case 0:
// should skip this if input file is .jpg or .jpeg (ignore case)
destFilename = fileNameNoExt + '-%d.png'
splitFiles = await Magick.Call([{'name': fileName, 'content':content}],
["convert", fileName, "-flatten", "-resize", "800", "-crop", "800x1000", "-quality", "100", "-scene", "0", destFilename]);
break;
// PNG is too large, try JPG
case 1:
destFilename = fileNameNoExt + '-%d.jpg'
splitFiles = await Magick.Call([{'name': fileName, 'content':content}],
["convert", fileName, "-flatten", "-resize", "800", "-crop", "800x1000", "-quality", "100", "-scene", "0", destFilename]);
break;
// jpeg too large, max file size each file
case 2:
destFilename = fileNameNoExt + '-%d.jpg'
let maxSize = Math.floor(20459520 / oldLineSplitCount)
let maxSizeStr = "jpeg:extent=" + maxSize
splitFiles = await Magick.Call([{'name': fileName, 'content':content}],
["convert", fileName, "-flatten", "-resize", "800", "-crop", "800x1000", "-define", maxSizeStr, "-scene", "0", destFilename]);
break;
}
processedImagesLine.push(...splitFiles);
}
if (doTapas.checked) {
let [fileName,content] = await ReadFile(files[fileIndex]);
let fileNameNoExt = fileName.substring(0, fileName.lastIndexOf('.'));
let destFilename = fileNameNoExt + '-%d.png'
if(IsJpeg(extension_first_file)){
destFilename = fileNameNoExt + '-%d.jpg'
}
let splitFiles = await Magick.Call([{'name': fileName, 'content':content}],
["convert", fileName, "-flatten", "-resize", ">940", "-crop", "x1280", "-quality", "100", "-scene", "0", destFilename]);
processedImagesTapas.push(...splitFiles);
}
}
catch(e)
{
if(!failedProcessing)
{
failedProcessing = true;
DoSomeTrack("convert_failed", extension_first_file, conversion_destination);
AlertIt("Error croppy could not format your file, old croppy may be up to the task, hit ok to go to https://old.croppy.duckdns.org", "https://old.croppy.duckdns.org");
}
}
}
if(!IsTooLarge(processedImagesLine) || failedProcessing){
break;
}
}
if(addPromo.checked){
processedImagesLine.push(await GetPromoImage());
}
GenerateZip(processedImagesLine, processedImagesTapas);
let processedImages = processedImagesLine;
processedImages.push(...processedImagesTapas);
for (let file of processedImages) {
let out_txt1 = file['blob'];
let img = document.createElement('img');
img.src = URL.createObjectURL(out_txt1);
img.className = "split-image"
img.name = file['name']
img.wasmResponse = file
imageHolder.appendChild(img);
}
CompletedImage("convert_complete", extension_first_file, conversion_destination);
SetProcessing(false);
}
};
control.addEventListener("change", function (event) {
event.preventDefault();
processFiles();
}, false);
</script>
<div id="footer">
<span style="text-align:left;"> Contact me, Twitter <a href="https://twitter.com/knic_knic">@knic_knic</a></span>
<br>
<span style="text-align:left;"> *Croppy does not transmit your images off your computer.</span>
<span style="float:right;">
<a href="https://github.com/KnicKnic/croppy">source/copyright</a>
</span>
<br>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="N6PPJQPQ9H78G">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
</form>
<br>
</div>
</body>
</html>