|
| 1 | +<!DOCTYPE html> |
| 2 | +<!-- |
| 3 | +
|
| 4 | +
|
| 5 | + ~~~ Thumbnails (FileAPI.Image ~~~ |
| 6 | + (NativeJS + FileAPI) |
| 7 | +
|
| 8 | +
|
| 9 | +--> |
| 10 | +<html> |
| 11 | +<head> |
| 12 | + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 13 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 14 | + |
| 15 | + <meta name="viewport" content="user-scalable=no, width=400, initial-scale=1, maximum-scale=1" /> |
| 16 | + <meta name="apple-mobile-web-app-capable" content="yes" /> |
| 17 | + <meta name="apple-mobile-web-app-status-bar-style" content="yes" /> |
| 18 | + <meta name="format-detection" content="email=no" /> |
| 19 | + <meta name="HandheldFriendly" content="true" /> |
| 20 | + |
| 21 | + <title>FileAPI :: Thumbnails :: example</title> |
| 22 | + |
| 23 | + <script> |
| 24 | + // Settings |
| 25 | + var FileAPI = { |
| 26 | + debug: true // debug mode |
| 27 | + , staticPath: '../dist/' |
| 28 | + }; |
| 29 | + </script> |
| 30 | + |
| 31 | + <script src="../dist/FileAPI.js"></script> |
| 32 | + <script src="../plugins/FileAPI.exif.js"></script> |
| 33 | + |
| 34 | + <link rel="stylesheet" href="_toolkit.css"/> |
| 35 | + <style> |
| 36 | + body { |
| 37 | + font-size: 15px; |
| 38 | + font-family: "Helvetica Neue"; |
| 39 | + } |
| 40 | + |
| 41 | + .thumb { |
| 42 | + float: left; |
| 43 | + border: 2px solid #ccc; |
| 44 | + margin: 10px; |
| 45 | + padding: 2px; |
| 46 | + position: relative; |
| 47 | + line-height: 0; |
| 48 | + z-index: -1; |
| 49 | + } |
| 50 | + .thumb label { |
| 51 | + color: #fff; |
| 52 | + text-align: center; |
| 53 | + text-shadow: 0 1px 1px #000; |
| 54 | + font-weight: bold; |
| 55 | + top: 45%; |
| 56 | + left: 0; |
| 57 | + right: 0; |
| 58 | + position: absolute; |
| 59 | + } |
| 60 | + </style> |
| 61 | + |
| 62 | +</head> |
| 63 | +<body> |
| 64 | + <div style="left: 0; right: 0; bottom: 0; position: fixed; box-shadow: 0 0 5px rgba(0,0,0,.65); background-color: #f3f3f3;"> |
| 65 | + <div style="padding: 5px 10px 10px"> |
| 66 | + <a href="../">← index</a> | |
| 67 | + <a href="./demo.html">demo</a> - |
| 68 | + <a href="./userpic.html">userpic</a> - |
| 69 | + <b>thumbnails</b> - |
| 70 | + <a href="./watermark.html">watermark</a> - |
| 71 | + <a href="./webcam.html">webcam</a> - |
| 72 | + <a href="./caman.html">caman.js</a> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div class="body"> |
| 77 | + <h2>Thumbnails</h2> |
| 78 | + |
| 79 | + <div style="text-align: center"> |
| 80 | + <div class="js-fileapi-wrapper"> |
| 81 | + <label for="browse" class="btn">Select photo (min 480x320)</label> |
| 82 | + <input id="browse" type="file" accept="image/*"/> |
| 83 | + </div> |
| 84 | + |
| 85 | + <div id="loading" class="loader" style="display: none; position: absolute; left: 45%; top: 30%"></div> |
| 86 | + <div id="thumbnails" style="margin-top: 30px;"></div> |
| 87 | + |
| 88 | + <div style="clear: both"> <br/><br/><br/></div> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + |
| 92 | + <script> |
| 93 | + (function (){ |
| 94 | + var processing = false; |
| 95 | + |
| 96 | + if( !(FileAPI.support.html5 || FileAPI.support.flash) ){ |
| 97 | + alert('Ooops, your browser does not support Flash and HTML5 :['); |
| 98 | + } |
| 99 | + |
| 100 | + function thumb(file, width, height, type){ |
| 101 | + var image = FileAPI.Image(file), label = width+'x'+height, callback; |
| 102 | + |
| 103 | + if( type ){ |
| 104 | + label += ' ('+type+')'; |
| 105 | + image.resize(width, height, type); |
| 106 | + } else if( width ){ |
| 107 | + image.preview(width, height); |
| 108 | + } else { |
| 109 | + label = 'original'; |
| 110 | + } |
| 111 | + |
| 112 | + image.get(function (err, img){ |
| 113 | + var el = document.createElement('div'); |
| 114 | + el.innerHTML = '<label>'+label+'</label>'; |
| 115 | + el.className = 'thumb'; |
| 116 | + el.appendChild(img); |
| 117 | + thumbnails.appendChild(el); |
| 118 | + callback && callback(); |
| 119 | + }); |
| 120 | + |
| 121 | + return function (then){ callback = then; }; |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + FileAPI.event.on(browse, 'change', function (evt){ |
| 126 | + var file = FileAPI.getFiles(evt)[0]; |
| 127 | + |
| 128 | + !processing && FileAPI.getInfo(file, function (err, info){ |
| 129 | + if( info.width >= 480 && info.height >= 320 ){ |
| 130 | + processing = true; |
| 131 | + thumbnails.innerHTML = ''; // clear |
| 132 | + loading.style.display = ''; |
| 133 | + |
| 134 | + // 100x100 |
| 135 | + thumb(file, 100, 100)(function (){ |
| 136 | + // 320x240 |
| 137 | + thumb(file, 320, 240)(function (){ |
| 138 | + // 480x320 by min side |
| 139 | + thumb(file, 480, 320, 'min')(function (){ |
| 140 | + // 480x320 by max side |
| 141 | + thumb(file, 480, 320, 'max')(function (){ |
| 142 | + // Original |
| 143 | + thumb(file); |
| 144 | + processing = false; |
| 145 | + loading.style.display = 'none'; |
| 146 | + }); |
| 147 | + }); |
| 148 | + }); |
| 149 | + }); |
| 150 | + } |
| 151 | + else { |
| 152 | + alert('Does not fit, you need more than: '+info.width+'x'+info.height); |
| 153 | + } |
| 154 | + }); |
| 155 | + }); |
| 156 | + })(); |
| 157 | + </script> |
| 158 | +</body> |
| 159 | +</html> |
0 commit comments