-
Notifications
You must be signed in to change notification settings - Fork 458
/
thumbnails.html
173 lines (148 loc) · 4.17 KB
/
thumbnails.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
<!DOCTYPE html>
<!--
~~~ Thumbnails (FileAPI.Image ~~~
(NativeJS + FileAPI)
-->
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="user-scalable=no, width=400, initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="yes" />
<meta name="format-detection" content="email=no" />
<meta name="HandheldFriendly" content="true" />
<title>FileAPI :: Thumbnails :: example</title>
<script>
// Settings
var FileAPI = {
debug: true // debug mode
, staticPath: '../dist/'
};
</script>
<script src="../dist/FileAPI.js"></script>
<script src="../plugins/FileAPI.exif.js"></script>
<link rel="stylesheet" href="toolkit.css"/>
<style>
body {
font-size: 15px;
font-family: "Helvetica Neue";
}
.thumb {
float: left;
border: 2px solid #ccc;
margin: 10px;
padding: 2px;
position: relative;
line-height: 0;
z-index: -1;
}
.thumb label {
color: #fff;
text-align: center;
text-shadow: 0 1px 1px #000;
font-weight: bold;
top: 45%;
left: 0;
right: 0;
position: absolute;
}
/* IE9/IE8 required */
.js-fileapi-wrapper { position: relative; }
.js-fileapi-wrapper input {
top: -10px;
right: -40px;
z-index: 2;
position: absolute;
cursor: pointer;
opacity: 0;
width: auto;
height: auto;
filter: alpha(opacity=0);
font-size: 50px;
}
</style>
</head>
<body>
<div style="left: 0; right: 0; bottom: 0; position: fixed; box-shadow: 0 0 5px rgba(0,0,0,.65); background-color: #f3f3f3;">
<div style="padding: 5px 10px 10px">
<a href="../">← index</a> |
<a href="./demo.html">demo</a> -
<a href="./userpic.html">userpic</a> -
<b>thumbnails</b> -
<a href="./watermark.html">watermark</a> -
<a href="./webcam.html">webcam</a> -
<a href="./caman.html">caman.js</a>
</div>
</div>
<div class="body">
<h2>Thumbnails</h2>
<div style="text-align: center">
<div class="js-fileapi-wrapper">
<label for="browse" class="btn">Select photo (min 480x320)</label>
<input id="browse" type="file" accept="image/*"/>
</div>
<div id="loading" class="loader" style="display: none; position: absolute; left: 45%; top: 30%"></div>
<div id="thumbnails" style="margin-top: 30px;"></div>
<div style="clear: both"> <br/><br/><br/></div>
</div>
</div>
<script>
(function (){
var processing = false;
if( !(FileAPI.support.html5 || FileAPI.support.flash) ){
alert('Ooops, your browser does not support Flash and HTML5 :[');
}
function thumb(file, width, height, type){
var image = FileAPI.Image(file), label = width+'x'+height, callback;
if( type ){
label += ' ('+type+')';
image.resize(width, height, type);
} else if( width ){
image.preview(width, height);
} else {
label = 'original';
}
image.get(function (err, img){
var el = document.createElement('div');
el.innerHTML = '<label>'+label+'</label>';
el.className = 'thumb';
el.appendChild(img);
thumbnails.appendChild(el);
callback && callback();
});
return function (then){ callback = then; };
}
FileAPI.event.on(browse, 'change', function (evt){
var file = FileAPI.getFiles(evt)[0];
!processing && FileAPI.getInfo(file, function (err, info){
if( info.width >= 480 && info.height >= 320 ){
processing = true;
thumbnails.innerHTML = ''; // clear
loading.style.display = '';
// 100x100
thumb(file, 100, 100)(function (){
// 320x240
thumb(file, 320, 240)(function (){
// 480x320 by min side
thumb(file, 480, 320, 'min')(function (){
// 480x320 by max side
thumb(file, 480, 320, 'max')(function (){
// Original
thumb(file);
processing = false;
loading.style.display = 'none';
});
});
});
});
}
else {
alert('Does not fit, you need more than: '+info.width+'x'+info.height);
}
});
});
})();
</script>
</body>
</html>