Selaa lähdekoodia

[ADD] initial commit

Gogs 7 vuotta sitten
commit
5fb185457c
6 muutettua tiedostoa jossa 671 lisäystä ja 0 poistoa
  1. 1 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 8 0
      __openerp__.py
  4. 21 0
      static/src/js/main.js
  5. 631 0
      static/src/lib/compress.js
  6. 10 0
      templates.xml

+ 1 - 0
__init__.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

BIN
__init__.pyc


+ 8 - 0
__openerp__.py

@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "eiru_image_optimizer",
+    'data': [
+        # 'security/ir.model.access.csv',
+        'templates.xml'
+    ]
+}

+ 21 - 0
static/src/js/main.js

@@ -0,0 +1,21 @@
+openerp.eiru_image_optimizer = function (instance, local) {
+    openerp.eiru_image_optimizer.compressor = new Compress(); 
+
+    if (openerp && openerp.web.form) {
+        openerp.web.form.FieldBinary.include({
+            on_file_change: function (e) {
+                var self = this;
+
+                openerp.eiru_image_optimizer.compressor.compress([e.target.files[0]], { 
+                    size: 4,
+                    quality: 0.70,
+                    maxWidth: 1920,
+                    maxHeight: 1920,
+                    resize: true
+                }).then(function (results) {
+                    self.on_file_uploaded(results[0].endSizeInMb * 1024 * 1024, results[0].alt, results[0].ext, results[0].data);
+                });
+            }
+        });
+    }
+}

+ 631 - 0
static/src/lib/compress.js

@@ -0,0 +1,631 @@
+var Compress =
+/******/ (function(modules) { // webpackBootstrap
+/******/ 	// The module cache
+/******/ 	var installedModules = {};
+
+/******/ 	// The require function
+/******/ 	function __webpack_require__(moduleId) {
+
+/******/ 		// Check if module is in cache
+/******/ 		if(installedModules[moduleId])
+/******/ 			return installedModules[moduleId].exports;
+
+/******/ 		// Create a new module (and put it into the cache)
+/******/ 		var module = installedModules[moduleId] = {
+/******/ 			exports: {},
+/******/ 			id: moduleId,
+/******/ 			loaded: false
+/******/ 		};
+
+/******/ 		// Execute the module function
+/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
+
+/******/ 		// Flag the module as loaded
+/******/ 		module.loaded = true;
+
+/******/ 		// Return the exports of the module
+/******/ 		return module.exports;
+/******/ 	}
+
+
+/******/ 	// expose the modules object (__webpack_modules__)
+/******/ 	__webpack_require__.m = modules;
+
+/******/ 	// expose the module cache
+/******/ 	__webpack_require__.c = installedModules;
+
+/******/ 	// __webpack_public_path__
+/******/ 	__webpack_require__.p = "";
+
+/******/ 	// Load entry module and return exports
+/******/ 	return __webpack_require__(0);
+/******/ })
+/************************************************************************/
+/******/ ([
+/* 0 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, __webpack_require__(1), __webpack_require__(2), __webpack_require__(3), __webpack_require__(4), __webpack_require__(5), __webpack_require__(6)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(module, require('./core/base64.js'), require('./core/converter.js'), require('./core/file.js'), require('./core/image.js'), require('./core/photo.js'), require('./core/rotate.js'));
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod, global.base64, global.converter, global.file, global.image, global.photo, global.rotate);
+	    global.Compress = mod.exports;
+	  }
+	})(this, function (module, _base, _converter, _file, _image, _photo, _rotate) {
+	  'use strict';
+
+	  var _base2 = _interopRequireDefault(_base);
+
+	  var _converter2 = _interopRequireDefault(_converter);
+
+	  var _file2 = _interopRequireDefault(_file);
+
+	  var _image2 = _interopRequireDefault(_image);
+
+	  var _photo2 = _interopRequireDefault(_photo);
+
+	  var _rotate2 = _interopRequireDefault(_rotate);
+
+	  function _interopRequireDefault(obj) {
+	    return obj && obj.__esModule ? obj : {
+	      default: obj
+	    };
+	  }
+
+	  function _toConsumableArray(arr) {
+	    if (Array.isArray(arr)) {
+	      for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
+	        arr2[i] = arr[i];
+	      }
+
+	      return arr2;
+	    } else {
+	      return Array.from(arr);
+	    }
+	  }
+
+	  function _classCallCheck(instance, Constructor) {
+	    if (!(instance instanceof Constructor)) {
+	      throw new TypeError("Cannot call a class as a function");
+	    }
+	  }
+
+	  var _createClass = function () {
+	    function defineProperties(target, props) {
+	      for (var i = 0; i < props.length; i++) {
+	        var descriptor = props[i];
+	        descriptor.enumerable = descriptor.enumerable || false;
+	        descriptor.configurable = true;
+	        if ("value" in descriptor) descriptor.writable = true;
+	        Object.defineProperty(target, descriptor.key, descriptor);
+	      }
+	    }
+
+	    return function (Constructor, protoProps, staticProps) {
+	      if (protoProps) defineProperties(Constructor.prototype, protoProps);
+	      if (staticProps) defineProperties(Constructor, staticProps);
+	      return Constructor;
+	    };
+	  }();
+
+	  var Compress = function () {
+	    function Compress() {
+	      _classCallCheck(this, Compress);
+	    }
+
+	    _createClass(Compress, [{
+	      key: 'attach',
+	      value: function attach(el, options) {
+	        var _this = this;
+
+	        return new Promise(function (resolve, reject) {
+	          var input = document.querySelector(el);
+	          input.setAttribute('accept', 'image/*');
+	          input.addEventListener('change', function (evt) {
+	            var output = _this.compress([].concat(_toConsumableArray(evt.target.files)), options);
+	            resolve(output);
+	          }, false);
+	        });
+	      }
+	    }, {
+	      key: 'compress',
+	      value: function compress(files, options) {
+	        function compressFile(file, options) {
+	          var photo = new _photo2.default(options);
+	          photo.start = window.performance.now();
+	          photo.alt = file.name;
+	          photo.ext = file.type;
+	          photo.startSize = file.size;
+
+	          return _rotate2.default.orientation(file).then(function (orientation) {
+	            photo.orientation = orientation;
+	            return _file2.default.load(file);
+	          }).then(compressImage(photo));
+	        }
+	        function compressImage(photo) {
+	          return function (src) {
+	            return _image2.default.load(src).then(function (img) {
+	              photo.startWidth = img.naturalWidth;
+	              photo.startHeight = img.naturalHeight;
+
+	              if (photo.resize) {
+	                var _Image$resize = _image2.default.resize(photo.maxWidth, photo.maxHeight)(img.naturalWidth, img.naturalHeight),
+	                    width = _Image$resize.width,
+	                    height = _Image$resize.height;
+
+	                photo.endWidth = width;
+	                photo.endHeight = height;
+	              } else {
+	                photo.endWidth = img.naturalWidth;
+	                photo.endHeight = img.naturalHeight;
+	              }
+	              return _converter2.default.imageToCanvas(photo.endWidth, photo.endHeight, photo.orientation)(img);
+	            }).then(function (canvas) {
+	              photo.iterations = 1;
+
+	              photo.base64prefix = _base2.default.prefix(photo.ext);
+	              return loopCompression(canvas, photo.startSize, photo.quality, photo.size, photo.minQuality, photo.iterations);
+	            }).then(function (base64) {
+	              photo.finalSize = _base2.default.size(base64);
+	              return _base2.default.data(base64);
+	            }).then(function (data) {
+	              photo.end = window.performance.now();
+	              var difference = photo.end - photo.start;
+
+	              return {
+	                data: data,
+	                prefix: photo.base64prefix,
+	                elapsedTimeInSeconds: difference / 1000,
+	                alt: photo.alt,
+	                initialSizeInMb: _converter2.default.size(photo.startSize).MB,
+	                endSizeInMb: _converter2.default.size(photo.finalSize).MB,
+	                ext: photo.ext,
+	                quality: photo.quality,
+	                endWidthInPx: photo.endWidth,
+	                endHeightInPx: photo.endHeight,
+	                initialWidthInPx: photo.startWidth,
+	                initialHeightInPx: photo.startHeight,
+	                sizeReducedInPercent: (photo.startSize - photo.finalSize) / photo.startSize * 100,
+	                iterations: photo.iterations
+	              };
+	            });
+	          };
+	        }
+	        function loopCompression(canvas, size) {
+	          var quality = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
+	          var targetSize = arguments[3];
+	          var targetQuality = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
+	          var iterations = arguments[5];
+
+	          var base64str = _converter2.default.canvasToBase64(canvas, quality);
+	          var newSize = _base2.default.size(base64str);
+
+	          iterations += 1;
+
+	          if (newSize > targetSize) {
+	            return loopCompression(canvas, newSize, quality - 0.1, targetSize, targetQuality, iterations);
+	          }
+
+	          if (quality > targetQuality) {
+	            return loopCompression(canvas, newSize, quality - 0.1, targetSize, targetQuality, iterations);
+	          }
+
+	          if (quality < 0.5) {
+	            return base64str;
+	          }
+	          return base64str;
+	        }
+	        return Promise.all(files.map(function (file) {
+	          return compressFile(file, options);
+	        }));
+	      }
+	    }], [{
+	      key: 'convertBase64ToFile',
+	      value: function convertBase64ToFile(base64, mime) {
+	        return _converter2.default.base64ToFile(base64, mime);
+	      }
+	    }]);
+
+	    return Compress;
+	  }();
+
+	  module.exports = Compress;
+	});
+
+/***/ }),
+/* 1 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.base64 = mod.exports;
+	  }
+	})(this, function (exports) {
+	  'use strict';
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+	  var size = function size(base64) {
+	    var len = base64.replace(/^data:image\/\w+;base64,/, '').length;
+	    return (len - 814) / 1.37;
+	  };
+
+	  var mime = function mime(base64) {
+	    return base64.split(';')[0].match(/jpeg|png|gif/)[0];
+	  };
+
+	  var data = function data(base64) {
+	    return base64.replace(/^data:image\/\w+;base64,/, '');
+	  };
+
+	  var prefix = function prefix(ext) {
+	    return 'data:' + ext + ';base64,';
+	  };
+
+	  exports.default = { size: size, mime: mime, data: data, prefix: prefix };
+	});
+
+/***/ }),
+/* 2 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.converter = mod.exports;
+	  }
+	})(this, function (exports) {
+	  'use strict';
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+
+	  var base64ToFile = function base64ToFile(base64) {
+	    var mime = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'image/jpeg';
+
+	    var byteString = window.atob(base64);
+	    var content = [];
+	    for (var i = 0; i < byteString.length; i++) {
+	      content[i] = byteString.charCodeAt(i);
+	    }
+	    return new window.Blob([new Uint8Array(content)], { type: mime });
+	  };
+
+	  var imageToCanvas = function imageToCanvas(width, height, orientation) {
+	    var canvas = document.createElement('canvas');
+	    var context = canvas.getContext('2d');
+
+	    canvas.width = width;
+	    canvas.height = height;
+
+
+	    return function (image) {
+	      if (!orientation || orientation > 8) {
+	        context.drawImage(image, 0, 0, canvas.width, canvas.height);
+	        return canvas;
+	      }
+	      if (orientation > 4) {
+	        canvas.width = height;
+	        canvas.height = width;
+	      }
+	      switch (orientation) {
+	        case 2:
+	          context.translate(width, 0);
+	          context.scale(-1, 1);
+	          break;
+	        case 3:
+	          context.translate(width, height);
+	          context.rotate(Math.PI);
+	          break;
+	        case 4:
+	          context.translate(0, height);
+	          context.scale(1, -1);
+	          break;
+	        case 5:
+	          context.rotate(0.5 * Math.PI);
+	          context.scale(1, -1);
+	          break;
+	        case 6:
+	          context.rotate(0.5 * Math.PI);
+	          context.translate(0, -height);
+	          break;
+	        case 7:
+	          context.rotate(0.5 * Math.PI);
+	          context.translate(width, -height);
+	          context.scale(-1, 1);
+	          break;
+	        case 8:
+	          context.rotate(-0.5 * Math.PI);
+	          context.translate(-width, 0);
+	          break;
+	      }
+	      if (orientation > 4) {
+	        context.drawImage(image, 0, 0, canvas.height, canvas.width);
+	      } else {
+	        context.drawImage(image, 0, 0, canvas.width, canvas.height);
+	      }
+	      return canvas;
+	    };
+	  };
+
+	  var canvasToBase64 = function canvasToBase64(canvas) {
+	    var quality = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.75;
+
+	    var base64 = canvas.toDataURL('image/jpeg', quality);
+	    return base64;
+	  };
+
+	  var size = function size(_size) {
+	    return {
+	      KB: _size / 1000,
+	      MB: _size / (1000 * 1000)
+	    };
+	  };
+
+	  exports.default = { base64ToFile: base64ToFile, imageToCanvas: imageToCanvas, canvasToBase64: canvasToBase64, size: size };
+	});
+
+/***/ }),
+/* 3 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.file = mod.exports;
+	  }
+	})(this, function (exports) {
+	  'use strict';
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+
+	  var load = function load(file) {
+	    return new Promise(function (resolve, reject) {
+	      var fileReader = new window.FileReader();
+	      fileReader.addEventListener('load', function (evt) {
+	        resolve(evt.target.result);
+	      }, false);
+
+	      fileReader.addEventListener('error', function (err) {
+	        reject(err);
+	      }, false);
+
+	      fileReader.readAsDataURL(file);
+	    });
+	  };
+
+	  exports.default = { load: load };
+	});
+
+/***/ }),
+/* 4 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.image = mod.exports;
+	  }
+	})(this, function (exports) {
+	  'use strict';
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+
+	  var load = function load(src) {
+	    return new Promise(function (resolve, reject) {
+	      var img = new window.Image();
+	      img.addEventListener('load', function () {
+	        resolve(img);
+	      }, false);
+
+	      img.addEventListener('error', function (err) {
+	        reject(err);
+	      }, false);
+
+	      img.src = src;
+	    });
+	  };
+
+	  var resize = function resize(targetWidth, targetHeight) {
+	    return function (width, height) {
+
+	      if (!targetWidth && !targetHeight) return { width: width, height: height };
+
+	      var outputWidth = Math.min(width, targetWidth);
+	      var outputHeight = Math.min(height, targetHeight);
+
+	      if (outputWidth) {
+	        var scaleWidth = width / outputWidth;
+	        var h = height / scaleWidth;
+
+	        return { width: outputWidth, height: h };
+	      } else {
+	        var scaleHeight = height / outputHeight;
+	        var w = width / scaleHeight;
+
+	        return { width: w, height: outputHeight };
+	      }
+	    };
+	  };
+
+	  exports.default = { load: load, resize: resize };
+	});
+
+/***/ }),
+/* 5 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.photo = mod.exports;
+	  }
+	})(this, function (exports) {
+	  "use strict";
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+
+	  function _classCallCheck(instance, Constructor) {
+	    if (!(instance instanceof Constructor)) {
+	      throw new TypeError("Cannot call a class as a function");
+	    }
+	  }
+
+	  var Photo = function Photo(_ref) {
+	    var _ref$quality = _ref.quality,
+	        quality = _ref$quality === undefined ? 0.75 : _ref$quality,
+	        _ref$size = _ref.size,
+	        size = _ref$size === undefined ? 2 : _ref$size,
+	        _ref$maxWidth = _ref.maxWidth,
+	        maxWidth = _ref$maxWidth === undefined ? 1920 : _ref$maxWidth,
+	        _ref$maxHeight = _ref.maxHeight,
+	        maxHeight = _ref$maxHeight === undefined ? 1920 : _ref$maxHeight,
+	        _ref$resize = _ref.resize,
+	        resize = _ref$resize === undefined ? true : _ref$resize;
+
+	    _classCallCheck(this, Photo);
+
+	    this.start = window.performance.now();
+	    this.end = null;
+
+	    this.alt = null;
+	    this.ext = null;
+	    this.startSize = null;
+	    this.startWidth = null;
+	    this.startHeight = null;
+
+	    this.size = size * 1000 * 1000;
+	    this.endSize = null;
+	    this.endWidth = null;
+	    this.endHeight = null;
+	    this.iterations = 0;
+	    this.base64prefix = null;
+
+	    this.quality = quality;
+	    this.resize = resize;
+	    this.maxWidth = maxWidth;
+	    this.maxHeight = maxHeight;
+	    this.orientation = 1;
+	  };
+
+	  exports.default = Photo;
+	});
+
+/***/ }),
+/* 6 */
+/***/ (function(module, exports, __webpack_require__) {
+
+	var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
+	  if (true) {
+	    !(__WEBPACK_AMD_DEFINE_ARRAY__ = [exports], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
+	  } else if (typeof exports !== "undefined") {
+	    factory(exports);
+	  } else {
+	    var mod = {
+	      exports: {}
+	    };
+	    factory(mod.exports);
+	    global.rotate = mod.exports;
+	  }
+	})(this, function (exports) {
+	  "use strict";
+
+	  Object.defineProperty(exports, "__esModule", {
+	    value: true
+	  });
+
+
+	  var orientation = function orientation(file) {
+	    return new Promise(function (resolve, reject) {
+	      var reader = new window.FileReader();
+
+	      reader.onload = function (event) {
+	        var view = new DataView(event.target.result);
+
+	        if (view.getUint16(0, false) !== 0xFFD8) {
+	          resolve(-2);
+	        }
+	        var length = view.byteLength;
+	        var offset = 2;
+
+	        while (offset < length) {
+	          var marker = view.getUint16(offset, false);
+	          offset += 2;
+
+	          if (marker === 0xFFE1) {
+	            if (view.getUint32(offset += 2, false) !== 0x45786966) {
+	              resolve(-1);
+	            }
+	            var little = view.getUint16(offset += 6, false) === 0x4949;
+	            offset += view.getUint32(offset + 4, little);
+	            var tags = view.getUint16(offset, little);
+	            offset += 2;
+
+	            for (var i = 0; i < tags; i++) {
+	              if (view.getUint16(offset + i * 12, little) === 0x0112) {
+	                resolve(view.getUint16(offset + i * 12 + 8, little));
+	              }
+	            }
+	          } else if ((marker & 0xFF00) !== 0xFF00) break;else offset += view.getUint16(offset, false);
+	        }
+	        resolve(-1);
+				};
+	      reader.readAsArrayBuffer(file.slice(0, 64 * 1024));
+	    });
+	  };
+
+	  exports.default = { orientation: orientation };
+	});
+
+/***/ })
+/******/ ]);

+ 10 - 0
templates.xml

@@ -0,0 +1,10 @@
+<openerp>
+    <data>
+         <template id="eiru_image_optimizer.assets" inherit_id="web.assets_backend">
+            <xpath expr="." position="inside">
+                <script type="text/javascript" src="/eiru_image_optimizer/static/src/lib/compress.js" /> 
+                <script type="text/javascript" src="/eiru_image_optimizer/static/src/js/main.js" />
+            </xpath>
+        </template>
+    </data>
+</openerp>