Skip to content

Commit 530a27c

Browse files
committed
+ iOS fix
1 parent f35f57a commit 530a27c

File tree

8 files changed

+426
-198
lines changed

8 files changed

+426
-198
lines changed

Gruntfile.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,27 @@ module.exports = function (grunt){
5858

5959
all: {
6060
src: [
61-
'lib/canvas-to-blob.js'
62-
, 'lib/FileAPI.core.js'
61+
'lib/FileAPI.core.js'
6362
, 'lib/FileAPI.Image.js'
6463
, 'lib/FileAPI.Form.js'
6564
, 'lib/FileAPI.XHR.js'
6665
, 'lib/FileAPI.Camera.js'
6766
, 'lib/FileAPI.Flash.js'
67+
, 'lib/load-image-ios.js'
68+
, 'lib/canvas-to-blob.js'
6869
],
6970
dest: 'dist/<%= pkg.name %>.js'
7071
},
7172

7273
html5: {
7374
src: [
74-
'lib/canvas-to-blob.js'
75-
, 'lib/FileAPI.core.js'
75+
'lib/FileAPI.core.js'
7676
, 'lib/FileAPI.Image.js'
7777
, 'lib/FileAPI.Form.js'
7878
, 'lib/FileAPI.XHR.js'
7979
, 'lib/FileAPI.Camera.js'
80+
, 'lib/load-image-ios.js'
81+
, 'lib/canvas-to-blob.js'
8082
],
8183
dest: 'dist/<%= pkg.name %>.html5.js'
8284
}

dist/FileAPI.html5.js

Lines changed: 110 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,6 @@
22
* FileAPI — a set of javascript tools for working with files. Multiupload, drag'n'drop and chunked file upload. Images: crop, resize and auto orientation by EXIF.
33
*/
44

5-
/*
6-
* JavaScript Canvas to Blob 2.0.3
7-
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
8-
*
9-
* Copyright 2012, Sebastian Tschan
10-
* https://blueimp.net
11-
*
12-
* Licensed under the MIT license:
13-
* http://www.opensource.org/licenses/MIT
14-
*
15-
* Based on stackoverflow user Stoive's code snippet:
16-
* http://stackoverflow.com/q/4998908
17-
*/
18-
19-
/*jslint nomen: true, regexp: true */
20-
/*global window, atob, Blob, ArrayBuffer, Uint8Array */
21-
22-
(function (window) {
23-
'use strict';
24-
var CanvasPrototype = window.HTMLCanvasElement &&
25-
window.HTMLCanvasElement.prototype,
26-
hasBlobConstructor = window.Blob && (function () {
27-
try {
28-
return Boolean(new Blob());
29-
} catch (e) {
30-
return false;
31-
}
32-
}()),
33-
hasArrayBufferViewSupport = hasBlobConstructor && window.Uint8Array &&
34-
(function () {
35-
try {
36-
return new Blob([new Uint8Array(100)]).size === 100;
37-
} catch (e) {
38-
return false;
39-
}
40-
}()),
41-
BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
42-
window.MozBlobBuilder || window.MSBlobBuilder,
43-
dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
44-
window.ArrayBuffer && window.Uint8Array && function (dataURI) {
45-
var byteString,
46-
arrayBuffer,
47-
intArray,
48-
i,
49-
mimeString,
50-
bb;
51-
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
52-
// Convert base64 to raw binary data held in a string:
53-
byteString = atob(dataURI.split(',')[1]);
54-
} else {
55-
// Convert base64/URLEncoded data component to raw binary data:
56-
byteString = decodeURIComponent(dataURI.split(',')[1]);
57-
}
58-
// Write the bytes of the string to an ArrayBuffer:
59-
arrayBuffer = new ArrayBuffer(byteString.length);
60-
intArray = new Uint8Array(arrayBuffer);
61-
for (i = 0; i < byteString.length; i += 1) {
62-
intArray[i] = byteString.charCodeAt(i);
63-
}
64-
// Separate out the mime component:
65-
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
66-
// Write the ArrayBuffer (or ArrayBufferView) to a blob:
67-
if (hasBlobConstructor) {
68-
return new Blob(
69-
[hasArrayBufferViewSupport ? intArray : arrayBuffer],
70-
{type: mimeString}
71-
);
72-
}
73-
bb = new BlobBuilder();
74-
bb.append(arrayBuffer);
75-
return bb.getBlob(mimeString);
76-
};
77-
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
78-
if (CanvasPrototype.mozGetAsFile) {
79-
CanvasPrototype.toBlob = function (callback, type) {
80-
callback(this.mozGetAsFile('blob', type));
81-
};
82-
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
83-
CanvasPrototype.toBlob = function (callback, type, quality) {
84-
callback(dataURLtoBlob(this.toDataURL(type, quality)));
85-
};
86-
}
87-
}
88-
89-
window.dataURLtoBlob = dataURLtoBlob;
90-
})(window);
91-
925
/*jslint evil: true */
936
/*global window, URL, webkitURL, ActiveXObject */
947

@@ -1886,8 +1799,11 @@
18861799
, buffer = image
18871800
, overlay = m.overlay
18881801
, queue = api.queue(function (){ fn(false, canvas); })
1802+
, renderImageToCanvas = api.renderImageToCanvas
18891803
;
18901804

1805+
// For `renderImageToCanvas`
1806+
image._type = this.file.type;
18911807

18921808
while( min(w/dw, h/dh) > 2 ){
18931809
w = (w/2 + 0.5)|0;
@@ -1898,24 +1814,25 @@
18981814
copy.height = h;
18991815

19001816
if( buffer !== image ){
1901-
copy.getContext('2d').drawImage(buffer, 0, 0, buffer.width, buffer.height, 0, 0, w, h);
1817+
renderImageToCanvas(copy, buffer, 0, 0, buffer.width, buffer.height, 0, 0, w, h);
19021818
buffer = copy;
19031819
}
19041820
else {
19051821
buffer = copy;
1906-
buffer.getContext('2d').drawImage(image, m.sx, m.sy, m.sw, m.sh, 0, 0, w, h);
1822+
renderImageToCanvas(buffer, image, m.sx, m.sy, m.sw, m.sh, 0, 0, w, h);
19071823
m.sx = m.sy = m.sw = m.sh = 0;
19081824
}
19091825
}
19101826

1827+
19111828
canvas.width = (deg % 180) ? dh : dw;
19121829
canvas.height = (deg % 180) ? dw : dh;
19131830

19141831
canvas.type = m.type;
19151832
canvas.quality = m.quality;
19161833

19171834
ctx.rotate(deg * Math.PI / 180);
1918-
ctx.drawImage(buffer
1835+
renderImageToCanvas(canvas, buffer
19191836
, m.sx, m.sy
19201837
, m.sw || buffer.width
19211838
, m.sh || buffer.height
@@ -1956,8 +1873,10 @@
19561873

19571874
queue.next();
19581875
};
1876+
19591877
api.event.on(img, 'error load abort', fn);
19601878
img.src = over.src;
1879+
19611880
if( img.complete ){
19621881
fn();
19631882
}
@@ -1974,8 +1893,8 @@
19741893
getMatrix: function (image){
19751894
var
19761895
m = api.extend({}, this.matrix)
1977-
, sw = m.sw = m.sw || image.videoWidth || image.width
1978-
, sh = m.sh = m.sh || image.videoHeight || image.height
1896+
, sw = m.sw = m.sw || image.videoWidth || image.naturalWidth || image.width
1897+
, sh = m.sh = m.sh || image.videoHeight || image.naturalHeight || image.height
19791898
, dw = m.dw = m.dw || sw
19801899
, dh = m.dh = m.dh || sh
19811900
, sf = sw/sh, df = dw/dh
@@ -2205,6 +2124,15 @@
22052124
};
22062125

22072126

2127+
/**
2128+
* For load-image-ios.js
2129+
*/
2130+
api.renderImageToCanvas = function (canvas, img, sx, sy, sw, sh, dx, dy, dw, dh){
2131+
canvas.getContext('2d').drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh);
2132+
return canvas;
2133+
};
2134+
2135+
22082136
// @export
22092137
api.support.canvas = api.support.transform = support;
22102138
api.Image = Image;
@@ -2983,4 +2911,94 @@
29832911
Camera.Shot = Shot;
29842912
api.Camera = Camera;
29852913
})(window, FileAPI);
2914+
2915+
/*
2916+
* JavaScript Canvas to Blob 2.0.5
2917+
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
2918+
*
2919+
* Copyright 2012, Sebastian Tschan
2920+
* https://blueimp.net
2921+
*
2922+
* Licensed under the MIT license:
2923+
* http://www.opensource.org/licenses/MIT
2924+
*
2925+
* Based on stackoverflow user Stoive's code snippet:
2926+
* http://stackoverflow.com/q/4998908
2927+
*/
2928+
2929+
/*jslint nomen: true, regexp: true */
2930+
/*global window, atob, Blob, ArrayBuffer, Uint8Array */
2931+
2932+
(function (window) {
2933+
'use strict';
2934+
var CanvasPrototype = window.HTMLCanvasElement &&
2935+
window.HTMLCanvasElement.prototype,
2936+
hasBlobConstructor = window.Blob && (function () {
2937+
try {
2938+
return Boolean(new Blob());
2939+
} catch (e) {
2940+
return false;
2941+
}
2942+
}()),
2943+
hasArrayBufferViewSupport = hasBlobConstructor && window.Uint8Array &&
2944+
(function () {
2945+
try {
2946+
return new Blob([new Uint8Array(100)]).size === 100;
2947+
} catch (e) {
2948+
return false;
2949+
}
2950+
}()),
2951+
BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
2952+
window.MozBlobBuilder || window.MSBlobBuilder,
2953+
dataURLtoBlob = (hasBlobConstructor || BlobBuilder) && window.atob &&
2954+
window.ArrayBuffer && window.Uint8Array && function (dataURI) {
2955+
var byteString,
2956+
arrayBuffer,
2957+
intArray,
2958+
i,
2959+
mimeString,
2960+
bb;
2961+
if (dataURI.split(',')[0].indexOf('base64') >= 0) {
2962+
// Convert base64 to raw binary data held in a string:
2963+
byteString = atob(dataURI.split(',')[1]);
2964+
} else {
2965+
// Convert base64/URLEncoded data component to raw binary data:
2966+
byteString = decodeURIComponent(dataURI.split(',')[1]);
2967+
}
2968+
// Write the bytes of the string to an ArrayBuffer:
2969+
arrayBuffer = new ArrayBuffer(byteString.length);
2970+
intArray = new Uint8Array(arrayBuffer);
2971+
for (i = 0; i < byteString.length; i += 1) {
2972+
intArray[i] = byteString.charCodeAt(i);
2973+
}
2974+
// Separate out the mime component:
2975+
mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
2976+
// Write the ArrayBuffer (or ArrayBufferView) to a blob:
2977+
if (hasBlobConstructor) {
2978+
return new Blob(
2979+
[hasArrayBufferViewSupport ? intArray : arrayBuffer],
2980+
{type: mimeString}
2981+
);
2982+
}
2983+
bb = new BlobBuilder();
2984+
bb.append(arrayBuffer);
2985+
return bb.getBlob(mimeString);
2986+
};
2987+
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
2988+
if (CanvasPrototype.mozGetAsFile) {
2989+
CanvasPrototype.toBlob = function (callback, type, quality) {
2990+
if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
2991+
callback(dataURLtoBlob(this.toDataURL(type, quality)));
2992+
} else {
2993+
callback(this.mozGetAsFile('blob', type));
2994+
}
2995+
};
2996+
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
2997+
CanvasPrototype.toBlob = function (callback, type, quality) {
2998+
callback(dataURLtoBlob(this.toDataURL(type, quality)));
2999+
};
3000+
}
3001+
}
3002+
window.dataURLtoBlob = dataURLtoBlob;
3003+
})(window);
29863004
if( typeof define === "function" && define.amd ){ define("FileAPI", [], function (){ return FileAPI; }); }

dist/FileAPI.html5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)