forked from dblackdblack/canvasResize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
224 lines (204 loc) · 10.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>canvasResize</title>
<meta name="description" content="Javascript Canvas Resize Plugin. It can work both with jQuery and Zepto. It's compatible with iOS6 and Android 2.3+" />
<meta name="keywords" content="javascript, jquery, zepto, canvas, image, resize" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link type="text/plain" rel="author" href="http://gokercebeci.com/humans.txt" />
<link rel="shortcut icon" href="http://gokercebeci.com/favicon.ico" type="image/x-icon" />
<style>
body { margin: 0; padding: 0; color:#333; font: normal 13px/1.264 sans-serif; }
img { border:0 }
.clearfix { clear:both; }
#devcontainer { margin: 20px auto; padding: 0 10px; width: 940px; }
pre, code {
display: block;
padding: 10px;
color: #eee;
border: 1px solid #222;
background: #333;
font-family: monospace, monospace;
_font-family: 'courier new', monospace;
font-size: 1em;
}
#area { float:left; width: 480px; }
.desc { float:right; width: 440px; }
.signature a { color:#555; text-decoration:none; }
.signature img { margin-right:5px; vertical-align: middle; }
</style>
<!-- jquery -->
<script src="zepto.min.js"></script>
</head>
<body>
<div id="devcontainer">
<!-- development area -->
<!-- SAMPLE -->
<section>
<h2>SAMPLE</h2>
<!-- description -->
<div class="desc">
<h1>jQuery canvasResize v1.2.0</h1>
<hr>
<p><b>canvasResize</b> is a plugin for client side image resizing.</p>
<p>It's compatible with iOS6 It can work
both with jQuery and Zepto</p>
<p>I fixed iOS6 Safari's image file rendering issue for large size image (over mega-pixel)
using few functions from
<a href="https://github.com/stomita/ios-imagefile-megapixel">ios-imagefile-megapixel</a><br/>
And fixed orientation issue by using
<a href="https://github.com/jseidelin/exif-js">exif-js</a></p>
<p><b>* Sorry, server side uploading option does not work on gokercebeci.com. You can test it on your own server.</b></p>
<p>I've only tested it on</p>
<ul>
<li><b>Chromium (24.0.1312.56)</b>, </li>
<li><b>Google Chrome (25.0.1364.68 beta)</b>, </li>
<li><b>Opera (12.14)</b>, </li>
<li><b>IOS 6.1.2</b></li>
</ul>
<p>and it works enough for me for now!</p>
<p>It is under MIT License and It requires "binaryajax.js" and "exif.js" to work which is also under the MPL License [http://www.nihilogic.dk/licenses/mpl-license.txt]</p>
<p class="signature"><a href="http://gokercebeci.com/dev/" title="developer">
<img src="http://geticon.org/of/gokercebeci.com" alt="developer" />
goker.cebeci, the developer</a></p>
<p class="signature"><a href="https://github.com/gokercebeci/canvasResize">
<img src="http://geticon.org/of/github.com" alt="github" />
fork it on github</a></p>
</div>
<!-- /description -->
<style>
#area div p { display: block; width: 300px; }
#area div p span { display: block; padding: 2px 0; width: 0; background: #193; text-align: center; }
#area b, #area img { display: block; }
#area img { margin: 10px 0; width: 300px; }
#area input { visibility: hidden; height: 0; }
#area u { display: block; padding: 15px; text-align: center; background: #ddd; border-radius: 6px; }
</style>
<div id="area">
<h3>canvasResize</h3>
<div>
<input name="photo" type="file"/>
<u>Choose file</u>
<p><span></span></p>
<i></i>
</div>
<script>
$().ready(function() {
$('#area u').click(function() {
$('input[name=photo]').trigger('click');
});
$('input[name=photo]').change(function(e) {
var file = e.target.files[0];
// RESET
$('#area p span').css('width', 0 + "%").html('');
$('#area img, #area canvas').remove();
$('#area i').html(JSON.stringify(e.target.files[0]).replace(/,/g, ", <br/>"));
// CANVAS RESIZING
canvasResize(file, {
width: 300,
height: 300,
crop: false,
quality: 80,
rotate: 0,
callback: function(data, width, height) {
// SHOW AS AN IMAGE
// =================================================
var img = new Image();
img.onload = function() {
$(this).css({
'margin': '10px auto',
'width': width,
'height': height
}).appendTo('#area div');
};
$(img).attr('src', data);
// /SHOW AS AN IMAGE
// =================================================
// IMAGE UPLOADING
// =================================================
// Create a new formdata
var fd = new FormData();
// Add file data
var f = canvasResize('dataURLtoBlob', data);
f.name = file.name;
fd.append($('#area input').attr('name'), f);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'uploader.php', true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("pragma", "no-cache");
//Upload progress
xhr.upload.addEventListener("progress", function(e) {
if (e.lengthComputable) {
var loaded = Math.ceil((e.loaded / e.total) * 100);
$('#area p span').css({
'width': loaded + "%"
}).html(loaded + "%");
}
}, false);
// File uploaded
xhr.addEventListener("load", function(e) {
var response = JSON.parse(e.target.responseText);
if (response.filename) {
// Complete
$('#area p span').html('done');
$('#area b').html(response.filename);
$('<img>').attr({
'src': response.filename
}).appendTo($('#area div'));
}
}, false);
// Send data
xhr.send(fd);
// /IMAGE UPLOADING
// =================================================
}
});
});
});
</script>
<script src="binaryajax.js"></script>
<script src="exif.js"></script>
<script src="canvasResize.js"></script>
</div>
<div class="clearfix"></div>
</section>
<!-- SAMPLE -->
<!-- USAGE -->
<section>
<h2>USAGE</h2>
<pre><code>
$('input[name=photo]').change(function(e) {
var file = e.target.files[0];
canvasResize(file, {
width: 300,
height: 0,
crop: false,
quality: 80,
//rotate: 90,
callback: function(data, width, height) {
$(img).attr('src', data);
}
});
});
</code></pre>
</section>
<!-- /USAGE -->
<!-- OPTIONS -->
<section>
<h2>OPTIONS</h2>
<pre><code>
width : 300, // Image width.
height : 0, // Image height, default 0 (flexible).
crop : false, // default false.
quality : 80, // Image quality default 80.
rotate : 90, // Image rotation default 0
callback : function(){},
</code></pre>
</section>
<!-- /OPTIONS -->
<!-- /development area -->
</div>
</body>
</html>