summaryrefslogtreecommitdiff
path: root/public/assets/js/vendor/renderToCanvas.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-11-22 19:16:52 -0500
committerJules Laplace <jules@okfoc.us>2016-11-22 19:16:52 -0500
commita92a313569e9dc623e18d5338ef8954c394e3d89 (patch)
tree2a3722642b53579ae428982267c9823b24512d64 /public/assets/js/vendor/renderToCanvas.js
parent654e25288a73bd41d1756771297c758e6fbd55a0 (diff)
fix orientation of iphone jpegs
Diffstat (limited to 'public/assets/js/vendor/renderToCanvas.js')
-rw-r--r--public/assets/js/vendor/renderToCanvas.js75
1 files changed, 73 insertions, 2 deletions
diff --git a/public/assets/js/vendor/renderToCanvas.js b/public/assets/js/vendor/renderToCanvas.js
index 376e61a..f223b02 100644
--- a/public/assets/js/vendor/renderToCanvas.js
+++ b/public/assets/js/vendor/renderToCanvas.js
@@ -8,8 +8,9 @@ function renderToCanvas(img, options) {
var ctx = canvas.getContext('2d')
var initialScale = options.scale || 1
// Scale to needed to constrain canvas to max size
- var scale = getScale(img.width * initialScale,
- img.height * initialScale, maxSize, maxSize)
+ // var scale = getScale(img.width * initialScale,
+ // img.height * initialScale, maxSize, maxSize)
+ var scale = 1
// Still need to apply the user defined scale
scale *= initialScale
var width = canvas.width = Math.round(img.width * scale)
@@ -104,6 +105,17 @@ function renderToCanvas(img, options) {
}
}
+var orientationToTransform = {
+ 1: { rotation: 0, mirror: false },
+ 2: { rotation: 0, mirror: true },
+ 3: { rotation: 180, mirror: false },
+ 4: { rotation: 180, mirror: true },
+ 5: { rotation: 90, mirror: true },
+ 6: { rotation: 90, mirror: false },
+ 7: { rotation: 270, mirror: true },
+ 8: { rotation: 270, mirror: false }
+}
+
function base64ToUint8Array(string, start, finish) {
var start = start || 0
var finish = finish || string.length
@@ -115,3 +127,62 @@ function base64ToUint8Array(string, start, finish) {
}
return buffer
}
+
+var dataUriToUint8Array = function(uri){
+ var data = uri.split(',')[1];
+ var bytes = atob(data);
+ var buf = new ArrayBuffer(bytes.length);
+ var u8 = new Uint8Array(buf);
+ for (var i = 0; i < bytes.length; i++) {
+ u8[i] = bytes.charCodeAt(i);
+ }
+ return u8
+}
+
+window.dataUriToBlob = (function(){
+ /**
+ * Blob constructor.
+ */
+
+ var Blob = window.Blob;
+
+ /**
+ * ArrayBufferView support.
+ */
+
+ var hasArrayBufferView = new Blob([new Uint8Array(100)]).size == 100;
+
+ /**
+ * Return a `Blob` for the given data `uri`.
+ *
+ * @param {String} uri
+ * @return {Blob}
+ * @api public
+ */
+
+ var dataUriToBlob = function(uri){
+ var data = uri.split(',')[1];
+ var bytes = atob(data);
+ var buf = new ArrayBuffer(bytes.length);
+ var arr = new Uint8Array(buf);
+ for (var i = 0; i < bytes.length; i++) {
+ arr[i] = bytes.charCodeAt(i);
+ }
+
+ if (!hasArrayBufferView) arr = buf;
+ var blob = new Blob([arr], { type: mime(uri) });
+ blob.slice = blob.slice || blob.webkitSlice;
+ return blob;
+ };
+
+ /**
+ * Return data uri mime type.
+ */
+
+ function mime(uri) {
+ return uri.split(';')[0].slice(5);
+ }
+
+ return dataUriToBlob;
+
+})()