From 15724bac1d538656062c0159ef495a075df46642 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 25 Nov 2016 22:12:27 -0500 Subject: resize --- public/assets/js/lib/views/UploadView.js | 38 ++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'public/assets/js/lib/views/UploadView.js') diff --git a/public/assets/js/lib/views/UploadView.js b/public/assets/js/lib/views/UploadView.js index 5acc39a..c622bb9 100644 --- a/public/assets/js/lib/views/UploadView.js +++ b/public/assets/js/lib/views/UploadView.js @@ -25,10 +25,44 @@ var UploadView = View.extend({ var file = files[0] if (! file) return - if ( ! file.type.match('image.*')) return + if (! file.type.match('image.*')) return this.file = file - app.views.home.PhotoView.load( file ) + if (file.type.match(/jpg|jpeg/)) { + this.fixOrientationAndLoad(file) + } + else { + var url = URL.createObjectURL(file) + this.load(url) + } + }, + + fixOrientationAndLoad: function(f){ + var reader = new FileReader() + var img = new Image () + + reader.addEventListener("load", function () { + img.src = reader.result + }, false) + + img.onload = function(){ + var max_side = Math.max(img.naturalWidth, img.naturalHeight) + var scale = Math.min(1280 / max_side, 1) + var canvas = renderToCanvas(img, { + correctOrientation: true, + scale: scale + }) + + var dataURI = canvas.toDataURL("image/jpeg", 0.8) + var blob = dataUriToBlob( dataURI ) + this.upload(blob) + }.bind(this) + + reader.readAsDataURL(f) + }, + + load: function( url ){ + app.views.home.PhotoView.load( url ) }, upload: function(file){ -- cgit v1.2.3-70-g09d2