-
Notifications
You must be signed in to change notification settings - Fork 883
/
index.html
545 lines (534 loc) · 31.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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html lang ="en">
<head>
<meta charset="UTF-8" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Croppie - a simple javascript image cropper - Foliotek</title>
<meta name="description" content="Croppie is an easy to use javascript image cropper.">
<meta property="og:title" content="Croppie - a javascript image cropper">
<meta property="og:type" content="website">
<meta property="og:url" content="https://foliotek.github.io/Croppie">
<meta property="og:description" content="Croppie is an easy to use javascript image cropper.">
<meta property="og:image" content="https://foliotek.github.io/Croppie/demo/hero.png">
<link href='//fonts.googleapis.com/css?family=Open+Sans:300,400,400italic,600,700' rel='stylesheet' type='text/css'>
<link rel="Stylesheet" type="text/css" href="demo/prism.css" />
<link rel="Stylesheet" type="text/css" href="bower_components/sweetalert/dist/sweetalert.css" />
<link rel="Stylesheet" type="text/css" href="croppie.css" />
<link rel="Stylesheet" type="text/css" href="demo/demo.css" />
<link rel="icon" href="//foliotek.github.io/favico-64.png" />
</head>
<body>
<section class="hero">
<a id="home" name="home"></a>
<div class="container">
<nav>
<a href="#options">Usage</a>
<a href="#documentation">Documentation</a>
<a href="#demos">Demos</a>
<a href="#browsers">About</a>
</nav>
<div class="grid">
<div class="col-1-2">
<h1>Croppie</h1>
<h2>
Croppie is a fast, easy to use image cropping plugin with tons of configuration options!
</h2>
<div class="buttons">
<a href="https://github.com/foliotek/croppie" class="btn">View on Github</a>
<button class="js-main-image">Get Result</button>
</div>
</div>
<div class="col-1-2">
<img class="demo-cropper" id="cropper-1" src="demo/demo-1.jpg" style="display: none;" />
</div>
</div>
</div>
</section>
<section class="simple">
<div class="section-header"><h2>The Basics</h2></div>
<div class="container">
<pre class="language-html"><code class="language-html"><div class="demo"></div>
<script>
$('.demo').croppie({
url: 'demo/demo-1.jpg',
});
</script>
<!-- or even simpler -->
<img class="my-image" src="demo/demo-1.jpg" />
<script>
$('.my-image').croppie();
</script>
</code></pre>
</div>
</section>
<section class="installation">
<a id="install" name="install"></a>
<div class="section-header"><h2>Installation</h2></div>
<div class="container">
<p><strong>NPM:</strong></p>
<pre class="language-javascript" style="width: 225px;"><code class="language-javascript">npm install croppie</code></pre>
<p><strong>Bower:</strong></p>
<pre class="language-javascript" style="width: 225px;"><code class="language-javascript">bower install croppie</code></pre>
<p><strong>Download:</strong></p>
<p><a href="https://github.com/Foliotek/Croppie/releases">Source</a></p>
<hr />
<p><strong>Then add the following elements to your page:</strong></p>
<pre class="language-html"><code class="language-html"><link rel="stylesheet" href="croppie.css" />
<script src="croppie.js"></script></code></pre>
</div>
</section>
<section>
<a name="options"></a>
<div class="section-header"><h2>Usage</h2></div>
<div class="container">
<p>You can initialize Croppie with the following code:</p>
<pre class="language-javascript"><code class="language-javascript">var c = new Croppie(document.getElementById('item'), opts);
// call a method
c.method(args);</code></pre>
<p>Or you can use jquery</p>
<pre class="language-javascript"><code class="language-javascript">$('#item').croppie(opts);
// call a method via jquery
$('#item').croppie(method, args);</code></pre>
</div>
</section>
<section class="documentation">
<a id="documentation" name="documentation"></a>
<div class="section-header"><h2>Documentation</h2></div>
<div class="container">
<section>
<h3>Options</h3>
<ul>
<li id="boundary">
<strong class="focus">boundary</strong><em>object</em>
<p>The outer container of the cropper</p>
<span class="default">Default</span>
<code class="language-html">will default to the size of the container</code>
</li>
<li id="customClass">
<strong class="focus">customClass</strong><em>string</em>
<p>A class of your choosing to add to the container to add custom styles to your croppie</p>
<span class="default">Default</span><code class="language-javascript">''</code>
</li>
<li id="enableExif">
<strong class="focus">enableExif</strong><em>boolean</em>
<p>Enable exif orientation reading. Tells Croppie to read exif orientation from the image data and orient the image correctly before rendering to the page.</p>
<p>Requires <a href="https://github.com/exif-js/exif-js">exif.js</a></p>
<span class="default">Default</span><code class="language-javascript">false</code>
</li>
<li id="enableOrientation">
<strong class="focus">enableOrientation</strong><em>boolean</em>
<p>Enable or disable support for specifying a custom orientation when binding images (See <code class="language-javascript">bind</code> method)</p>
<span class="default">Default</span>
<code class="language-javascript">false</code>
</li>
<li id="enableResize">
<strong class="focus">enableResize</strong><em>boolean</em>
<p>Enable or disable support for resizing the viewport area.</p>
<span class="default">Default</span>
<code class="language-javascript">false</code>
</li>
<li id="enableZoom">
<strong class="focus">enableZoom</strong><em>boolean</em>
<p>Enable zooming functionality. If set to false - scrolling and pinching would not zoom.</p>
<span class="default">Default</span><code class="language-javascript">true</code>
</li>
<li id="enforceBoundary">
<strong class="focus">enforceBoundary</strong><em>boolean</em><i>* Experimental</i>
<p>Restricts zoom so image cannot be smaller than viewport</p>
<span class="default">Default</span><code class="language-javascript">true</code>
</li>
<li id="mouseWheelZoom">
<strong class="focus">mouseWheelZoom</strong><em>bool/string</em>
<p>Enable or disable the ability to use the mouse wheel to zoom in and out on a croppie instance. If <code class="language-javascript">'ctrl'</code> is passed mouse wheel will only work while control keyboard is pressed</p>
<span class="default">Default</span><code class="language-javascript">true</code>
</li>
<li id="showZoomer">
<strong class="focus">showZoomer</strong><em>boolean</em>
<p>Hide or Show the zoom slider</p>
<span class="default">Default</span><code class="language-javascript">true</code>
</li>
<li id="viewport">
<strong class="focus">viewport</strong><em>object</em>
<p>The inner container of the coppie. The visible part of the image</p>
<span class="default">Default</span>
<code class="language-javascript">{
width: 100,
height: 100,
type: 'square'
}</code>
<br /><br />
<span class="default">Valid type values:</span><code class="language-javascript">'square' 'circle'</code>
</li>
</ul>
</section>
<section>
<h3>Methods</h3>
<ul>
<li id="get">
<strong class="focus">get()</strong><em>object</em>
<p>Get the crop points, and the zoom of the image.</p>
</li>
<li id="bind">
<strong class="focus">bind({ url, points, orientation, zoom })</strong><em>Promise</em>
<p>Bind an image to the croppie. Returns a promise to be resolved when the image has been loaded and the croppie has been initialized.</p>
<span class="default">Parameters</span>
<br />
<ul class="parameter-list">
<li><code class="language-javascript">url</code> URL to image</li>
<li><code class="language-javascript">points</code> Array of points that translate into <code class="language-javascript">[topLeftX, topLeftY, bottomRightX, bottomRightY]</code></li>
<li><code class="language-javascript">zoom</code> Apply zoom after image has been bound </li>
<li><code class="language-javascript">orientation</code> Custom orientation, applied after exif orientation (if enabled). Only works with
<code class="language-javascript">enableOrientation</code> option enabled (see 'Options').
<br />
Valid options are:
<ul>
<li><code class="language-javascript">1</code> unchanged</li>
<li><code class="language-javascript">2</code> flipped horizontally</li>
<li><code class="language-javascript">3</code> rotated 180 degrees</li>
<li><code class="language-javascript">4</code> flipped vertically</li>
<li><code class="language-javascript">5</code> flipped horizontally, then rotated left by 90 degrees</li>
<li><code class="language-javascript">6</code> rotated clockwise by 90 degrees</li>
<li><code class="language-javascript">7</code> flipped horizontally, then rotated right by 90 degrees</li>
<li><code class="language-javascript">8</code> rotated counter-clockwise by 90 degrees</li>
</ul>
</li>
</ul>
</li>
<li id="destroy">
<strong class="focus">destroy()</strong><em></em>
<p>Destroy a croppie instance and remove it from the DOM</p>
</li>
<li id="result">
<strong class="focus">result({ type, size, format, quality, circle })</strong><em>Promise</em>
<p>Get the resulting crop of the image.</p>
<span class="default">Parameters</span>
<br />
<ul class="parameter-list">
<li>
<code class="language-javascript">type</code> The type of result to return defaults to <code class="language-javascript">'canvas'</code>
</li>
<li class="values">
<code class="language-javascript">'base64'</code> returns a the cropped image encoded in base64
</li>
<li class="values">
<code class="language-javascript">'html'</code> returns html of the image positioned within an div of hidden overflow
</li>
<li class="values">
<code class="language-javascript">'blob'</code> returns a blob of the cropped image
</li>
<li class="values">
<code class="language-javascript">'rawcanvas'</code> returns the canvas element allowing you to manipulate prior to getting the resulted image
</li>
<li>
<code class="language-javascript">size</code> The size of the cropped image defaults to <code class="language-javascript">'viewport'</code>
</li>
<li class="values">
<code class="language-javascript">'viewport'</code> the size of the resulting image will be the same width and height as the viewport
</li>
<li class="values">
<code class="language-javascript">'original'</code> the size of the resulting image will be at the original scale of the image
</li>
<li class="values">
<code class="language-javascript">{width, height}</code> an object defining the width and height. If only one dimension is specified, the other will be calculated using the viewport aspect ratio.
</li>
<li>
<code class="language-javascript">format</code> Indicating the image format.
</li>
<li class="values">
<span class="default">Default:</span><code class="language-javascript">'png'</code>
</li>
<li class="values">
<span class="default">Valid values:</span><code class="language-javascript">'jpeg'|'png'|'webp'</code>
</li>
<li>
<code class="language-javascript">quality</code> Number between 0 and 1 indicating image quality.
</li>
<li class="values">
<span class="default">Default:</span><code class="language-javascript">1</code>
</li>
<li>
<code class=" language-javascript">circle</code> force the result to be cropped into a circle
</li>
<li class="values">
<span class="default">Valid Values:</span><code class="language-javascript">true</code><code class="language-javascript">false</code>
</li>
</ul>
</li>
<li id="rotate">
<strong class="focus">rotate(degrees)</strong><em></em>
<p>Rotate the image by a specified degree amount. Only works with <code class="language-javascript">enableOrientation</code> option enabled (see 'Options').</p>
<ul class="parameter-list">
<li>
<code class="language-javascript">degrees</code> <span class="default">Valid Values:</span><code>90, 180, 270, -90, -180, -270</code>
</li>
</ul>
</li>
<li id="setZoom">
<strong class="focus">setZoom(value)</strong><em></em>
<p>Set the zoom of a Croppie instance. The value passed in is still restricted to the min/max set by Croppie.</p>
<ul class="parameter-list">
<li>
<code class="language-javascript">value</code> a floating point to scale the image within the croppie. Must be between a min and max value set by croppie.
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Events</h3>
<ul>
<li id="update">
<strong class="focus">update(croppie)</strong><em>Croppie</em>
<p>Triggered when a drag or zoom occurs</p>
<pre class="language-javascript"><code class="language-javascript">
$('.my-croppie').on('update.croppie', function(ev, cropData) {});
// or
document.getElementById('another-croppie').addEventListener('update', function(ev) { var cropData = ev.detail; });
</code></pre>
</li>
</ul>
</section>
</div>
</section>
<section>
<a id="demos" name="demos"></a>
<div class="section-header">
<h2>Demos</h2>
</div>
<div class="demo-wrap">
<div class="container">
<div class="grid">
<div class="col-1-2">
<strong>Basic Example</strong>
<pre class="language-javascript"><code class="language-javascript">
var basic = $('#demo-basic').croppie({
viewport: {
width: 150,
height: 200
}
});
basic.croppie('bind', {
url: 'demo/cat.jpg',
points: [77,469,280,739]
});
//on button click
basic.croppie('result', 'html').then(function(html) {
// html is div (overflow hidden)
// with img positioned inside.
});</code></pre>
<div class="actions">
<button class="basic-result">Result</button>
<input type="number" class="basic-width" placeholder="width" /> x <input type="number" class="basic-height" placeholder="height" />
</div>
</div>
<div class="col-1-2">
<div id="demo-basic"></div>
</div>
</div>
</div>
</div>
<div class="demo-wrap">
<div class="container">
<div class="grid">
<div class="col-1-2">
<div id="vanilla-demo"></div>
</div>
<div class="col-1-2">
<strong>Vanilla Example</strong>
<pre class="language-javascript"><code class="language-javascript">
var el = document.getElementById('vanilla-demo');
var vanilla = new Croppie(el, {
viewport: { width: 100, height: 100 },
boundary: { width: 300, height: 300 },
showZoomer: false,
enableOrientation: true
});
vanilla.bind({
url: 'demo/demo-2.jpg',
orientation: 4
});
//on button click
vanilla.result('blob').then(function(blob) {
// do something with cropped blob
});</code></pre>
<div class="actions">
<button class="vanilla-result">Result</button>
<button class="vanilla-rotate" data-deg="-90">Rotate Left</button>
<button class="vanilla-rotate" data-deg="90">Rotate Right</button>
</div>
</div>
</div>
</div>
</div>
<div class="demo-wrap">
<div class="container">
<div class="grid">
<div class="col-1-2">
<strong>Resizer Example</strong>
<pre class="language-javascript"><code class="language-javascript">
var el = document.getElementById('resizer-demo');
var resize = new Croppie(el, {
viewport: { width: 100, height: 100 },
boundary: { width: 300, height: 300 },
showZoomer: false,
enableResize: true,
enableOrientation: true,
mouseWheelZoom: 'ctrl'
});
resize.bind({
url: 'demo/demo-2.jpg',
});
//on button click
resize.result('blob').then(function(blob) {
// do something with cropped blob
});</code></pre>
<div class="actions">
<button class="resizer-result">Result</button>
</div>
</div>
<div class="col-1-2">
<div id="resizer-demo"></div>
</div>
</div>
</div>
</div>
<div class="demo-wrap upload-demo">
<div class="container">
<div class="grid">
<div class="col-1-2">
<strong>Upload Example (with exif orientation compatability)</strong>
<pre class="language-javascript"><code class="language-javascript">
$uploadCrop = $('#upload-demo').croppie({
enableExif: true,
viewport: {
width: 200,
height: 200,
type: 'circle'
},
boundary: {
width: 300,
height: 300
}
});</code></pre>
<div class="actions">
<a class="btn file-btn">
<span>Upload</span>
<input type="file" id="upload" value="Choose a file" accept="image/*" />
</a>
<button class="upload-result">Result</button>
</div>
</div>
<div class="col-1-2">
<div class="upload-msg">
Upload a file to start cropping
</div>
<div class="upload-demo-wrap">
<div id="upload-demo"></div>
</div>
</div>
</div>
</div>
</div>
<div class="demo-wrap hidden-demo">
<div class="container">
<div class="grid">
<div class="col-1-2">
<strong>Hidden Example</strong>
<p>When binding a croppie element that isn't visible, i.e., in a modal - you'll need to call bind again on your croppie element, to indicate to croppie that the position has changed and it needs to recalculate its points.</p>
<pre class="language-javascript"><code class="language-javascript">
$('#hidden-demo').croppie('bind')</code></pre>
<div class="actions">
<button class="show-hidden">Toggle Croppie</button>
</div>
</div>
<div class="col-1-2">
<div id="hidden-demo" style="display: none;"></div>
</div>
</div>
</div>
</div>
</section>
<section class="important-notes">
<a id="important-notes" name="important-notes"></a>
<div class="section-header"><h2>Important Notes</h2></div>
<div class="container">
<article>
<a id="cors" name="cors"></a>
<h3>Image Hosting & Cross Origin Errors</h3>
<p>Croppie uses <code class="language-javascript">canvas.drawImage(...)</code> to manipulate images. Thus, images must obey the CORS policy. More info can be found <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image">here</a>.</p>
</article>
<article>
<a id="visibility" name="visibility"></a>
<h3>Visibility and Binding</h3>
<p>Croppie is dependent on it's container being visible when the <a href="#bind">bind</a> method is called. This can be an issue when your croppie component is inside a modal that isn't shown. Let's take the bootstrap modal for example..</p>
<pre class="language-javascript"><code class="language-javascript">
var myCroppie = $('#my-croppie').croppie(opts);
$('#my-modal').on('shown.bs.modal', function(){
myCroppie.croppie('bind', bindOpts);
});
</code></pre>
<p>If you are having issues getting the correct crop result, and your croppie instance is shown inside of a modal, try taking your croppie out of the modal and see if your issues persist. If they don't, then make sure that your bind method is called after the modal is done animating.</p>
</article>
</div>
</section>
<section class="browsers">
<a id="browsers" name="browsers"></a>
<div class="section-header">
<h2>Browser Support</h2>
</div>
<div class="container">
<p>Croppie is supported in the following browsers:</p>
<ul>
<li>Firefox 10+</li>
<li>Chrome 12+</li>
<li>IE 10+</li>
<li>Edge</li>
<li>Safari 4+</li>
<li>Opera 15+</li>
<li>iOS</li>
<li>Android</li>
</ul>
</div>
</section>
<section class="who">
<a id="who" name="who"></a>
<div class="section-header">
<h2>Who</h2>
</div>
<div class="container">
<p>
Croppie was built by <a href="http://www.foliotek.com">Foliotek</a> for use in Foliotek Presentation.
</p>
<p>
Please submit any issues or questions on <a href="http://github.com/foliotek/Croppie/issues">Github.</a>
</p>
<p>
Check out some of our other open source tools: <a href="//foliotek.github.io/AjaxQ">AjaxQ</a> | <a href="//foliotek.github.io/LTI-Tester">LTI Tester</a>
</p>
</div>
</section>
<footer>
Copyright © <span id="year">2017</span> | Foliotek
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="bower_components/jquery/dist/jquery.min.js"><\/script>')</script>
<script src="demo/prism.js"></script>
<script src="bower_components/sweetalert/dist/sweetalert.min.js"></script>
<script src="croppie.js"></script>
<script src="demo/demo.js"></script>
<script src="bower_components/exif-js/exif.js"></script>
<script>
document.getElementById('year').innerHTML = (new Date).getFullYear();
Demo.init();
</script>
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-2398527-4');ga('send','pageview');
</script>
<a href="https://github.com/foliotek/croppie" class="github-corner"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1); -webkit-transform: sale(-1, 1);"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style></a>
</body>
</html>