diff --git a/dist/defaults.js b/dist/defaults.js index d03d842..bafa867 100644 --- a/dist/defaults.js +++ b/dist/defaults.js @@ -106,7 +106,7 @@ __webpack_require__.r(__webpack_exports__); // 16MB maxWidth: 500, maxHeight: 500, - quality: 0.5, + quality: 0.92, base64OutputType: false, blobOutputType: true, allowedFileTypes: ["jpg", "png", "jpeg"] diff --git a/dist/defaults.js.map b/dist/defaults.js.map index 12961a3..ee81884 100644 --- a/dist/defaults.js.map +++ b/dist/defaults.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./src/defaults.js"],"names":["sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;AClFA;AAAe;AACbA,WAAS,EAAE,QADE;AACQ;AACrBC,UAAQ,EAAE,GAFG;AAGbC,WAAS,EAAE,GAHE;AAIbC,SAAO,EAAE,GAJI;AAKbC,kBAAgB,EAAE,KALL;AAMbC,gBAAc,EAAE,IANH;AAObC,kBAAgB,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,MAAf;AAPL,CAAf,E","file":"./defaults.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.5,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./src/defaults.js"],"names":["sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;AClFA;AAAe;AACbA,WAAS,EAAE,QADE;AACQ;AACrBC,UAAQ,EAAE,GAFG;AAGbC,WAAS,EAAE,GAHE;AAIbC,SAAO,EAAE,IAJI;AAKbC,kBAAgB,EAAE,KALL;AAMbC,gBAAc,EAAE,IANH;AAObC,kBAAgB,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,MAAf;AAPL,CAAf,E","file":"./defaults.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.92,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index ac0f7ce..0b0a315 100644 --- a/dist/index.js +++ b/dist/index.js @@ -153,7 +153,7 @@ __webpack_require__.r(__webpack_exports__); // 16MB maxWidth: 500, maxHeight: 500, - quality: 0.5, + quality: 0.92, base64OutputType: false, blobOutputType: true, allowedFileTypes: ["jpg", "png", "jpeg"] diff --git a/dist/index.js.map b/dist/index.js.map index 6c03021..4bffe0b 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./src/utils.js","webpack:///./src/defaults.js","webpack:///./src/resizeImage.js","webpack:///./src/index.js"],"names":["validateFileType","fileType","options","accepted","allowedFileTypes","forEach","allowedFileType","regEx","RegExp","test","validateFileSize","imageSize","sizeLimit","base64ToBlob","base64","sliceSize","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","push","blob","Blob","type","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","resizeImageFile","file","resolve","_reject","name","reader","FileReader","readAsArrayBuffer","onload","event","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","ctx","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defaultVal"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;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AL,GAAeA,OAAf;AACD;AAED;;;;;;AAaa6E,6EAAf,E","file":"./index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.5,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./src/utils.js","webpack:///./src/defaults.js","webpack:///./src/resizeImage.js","webpack:///./src/index.js"],"names":["validateFileType","fileType","options","accepted","allowedFileTypes","forEach","allowedFileType","regEx","RegExp","test","validateFileSize","imageSize","sizeLimit","base64ToBlob","base64","sliceSize","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","push","blob","Blob","type","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","resizeImageFile","file","resolve","_reject","name","reader","FileReader","readAsArrayBuffer","onload","event","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","ctx","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defaultVal"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;QCVA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAO,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACrD,MAAIC,QAAQ,GAAG,KAAf;AACAD,SAAO,CAACE,gBAAR,CAAyBC,OAAzB,CAAiC,UAACC,eAAD,EAAqB;AACpD,QAAMC,KAAK,GAAG,IAAIC,MAAJ,CAAW,WAAWF,eAAtB,CAAd;AACA,QAAIC,KAAK,CAACE,IAAN,CAAWR,QAAX,CAAJ,EAA0BE,QAAQ,GAAG,IAAX;AAC3B,GAHD;AAIA,SAAOA,QAAP;AACD,CAPM;AASA,IAAMO,gBA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,CAACgC,SAAR,GAAoBhC,OAAO,CAACgC,SAAR,IAAqBkD,iDAAU,CAAClD,SAApD;AACAhC,SAAO,CAACiC,OAAR,GAAkBjC,OAAO,CAACiC,OAAR,IAAmBiD,iDAAU,CAACjD,OAAhD,CAJmB,CAIsC;;AACzDjC,SAAO,CAACkC,gBAAR,GACElC,OAAO,CAACkC,gBAAR,IAA4BgD,iDAAU,CAAChD,gBADzC,CALmB,CAMwC;;AAC3DlC,SAAO,CAACmC,cAAR,GACEnC,OAAO,CAACmC,cAAR,IAA0B+C,iDAAU,CAAC/C,cADvC,CAPmB,CAQoC;;AACvDnC,SAAO,CAACE,gBAAR,GACEF,OAAO,CAACE,gBAAR,IAA4BgF,iDAAU,CAAChF,gBADzC,CATmB,CAUwC;;AAC3D,OAAKF,OAAL,GAAeA,OAAf;AACD;AAED;;;;;;AAaa6E,6EAAf,E","file":"./index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 3);\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.92,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/lib/transform-image-js.js b/lib/transform-image-js.js index 6afe264..b1dded5 100644 --- a/lib/transform-image-js.js +++ b/lib/transform-image-js.js @@ -102,7 +102,7 @@ __webpack_require__.d(__webpack_exports__, "TransformImage", function() { return // 16MB maxWidth: 500, maxHeight: 500, - quality: 0.5, + quality: 0.92, base64OutputType: false, blobOutputType: true, allowedFileTypes: ["jpg", "png", "jpeg"] diff --git a/lib/transform-image-js.map b/lib/transform-image-js.map index 23f61e9..ef3577a 100644 --- a/lib/transform-image-js.map +++ b/lib/transform-image-js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://transformImageJS/webpack/bootstrap","webpack://transformImageJS/./src/defaults.js","webpack://transformImageJS/./src/utils.js","webpack://transformImageJS/./src/resizeImage.js","webpack://transformImageJS/./src/index.js"],"names":["sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes","validateFileType","fileType","options","accepted","forEach","allowedFileType","regEx","RegExp","test","validateFileSize","imageSize","base64ToBlob","base64","sliceSize","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","push","blob","Blob","type","resizeImageFile","file","resolve","_reject","name","reader","FileReader","readAsArrayBuffer","onload","event","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","ctx","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defaultVal"],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;Q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;;;AAaasE,0DAAf,E","file":"transform-image-js.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.5,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://transformImageJS/webpack/bootstrap","webpack://transformImageJS/./src/defaults.js","webpack://transformImageJS/./src/utils.js","webpack://transformImageJS/./src/resizeImage.js","webpack://transformImageJS/./src/index.js"],"names":["sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes","validateFileType","fileType","options","accepted","forEach","allowedFileType","regEx","RegExp","test","validateFileSize","imageSize","base64ToBlob","base64","sliceSize","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","i","charCodeAt","byteArray","Uint8Array","push","blob","Blob","type","resizeImageFile","file","resolve","_reject","name","reader","FileReader","readAsArrayBuffer","onload","event","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","ctx","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defa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I,SAAO,CAACH,gBAAR,GACEG,OAAO,CAACH,gBAAR,IAA4B8E,QAAU,CAAC9E,gBADzC,CATmB,CAUwC;;AAC3D,OAAKG,OAAL,GAAeA,OAAf;AACD;AAED;;;;;;AAaasE,0DAAf,E","file":"transform-image-js.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.92,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/lib/transform-image-js.min.js b/lib/transform-image-js.min.js index d204292..8e93fb7 100644 --- a/lib/transform-image-js.min.js +++ b/lib/transform-image-js.min.js @@ -1,2 +1,2 @@ -window.transformImageJS=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"TransformImage",(function(){return c}));var r={sizeLimit:16777216,maxWidth:500,maxHeight:500,quality:.5,base64OutputType:!1,blobOutputType:!0,allowedFileTypes:["jpg","png","jpeg"]},i=function(e,t){var n=!1;return t.allowedFileTypes.forEach((function(t){new RegExp("image/"+t).test(e)&&(n=!0)})),n},a=function(e,t){if(e>t.sizeLimit)throw"Please upload an image of size less than "+t.sizeLimit/1048576+"MB"},o=function(e,t){var n=new RegExp("^data:"+t+";base64,");e=e.replace(n,"");for(var r=atob(e),i=[],a=0;aa?i>n.maxWidth&&(a=Math.round(a*=n.maxWidth/i),i=n.maxWidth):a>n.maxHeight&&(i=Math.round(i*=n.maxHeight/a),a=n.maxHeight),r.width=i,r.height=a,r.getContext("2d").drawImage(e,0,0,i,a),{output:r.toDataURL(t,n.quality),metadata:{originalHeight:e.height,originalWidth:e.width,resizedHeight:a,resizedWidth:i}}};var c=function e(t){var n,i,a,o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a=function(e){return new Promise((function(t,n){l(e,o.options,t,n).catch((function(e){n(e)}))}))},(i="resizeImage")in(n=this)?Object.defineProperty(n,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[i]=a,t.sizeLimit=t.sizeLimit||r.sizeLimit,t.maxWidth=t.maxWidth||r.maxWidth,t.maxHeight=t.maxHeight||r.maxHeight,t.quality=t.quality||r.quality,t.base64OutputType=t.base64OutputType||r.base64OutputType,t.blobOutputType=t.blobOutputType||r.blobOutputType,t.allowedFileTypes=t.allowedFileTypes||r.allowedFileTypes,this.options=t}}]); +window.transformImageJS=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";n.r(t),n.d(t,"TransformImage",(function(){return c}));var r={sizeLimit:16777216,maxWidth:500,maxHeight:500,quality:.92,base64OutputType:!1,blobOutputType:!0,allowedFileTypes:["jpg","png","jpeg"]},i=function(e,t){var n=!1;return t.allowedFileTypes.forEach((function(t){new RegExp("image/"+t).test(e)&&(n=!0)})),n},a=function(e,t){if(e>t.sizeLimit)throw"Please upload an image of size less than "+t.sizeLimit/1048576+"MB"},o=function(e,t){var n=new RegExp("^data:"+t+";base64,");e=e.replace(n,"");for(var r=atob(e),i=[],a=0;aa?i>n.maxWidth&&(a=Math.round(a*=n.maxWidth/i),i=n.maxWidth):a>n.maxHeight&&(i=Math.round(i*=n.maxHeight/a),a=n.maxHeight),r.width=i,r.height=a,r.getContext("2d").drawImage(e,0,0,i,a),{output:r.toDataURL(t,n.quality),metadata:{originalHeight:e.height,originalWidth:e.width,resizedHeight:a,resizedWidth:i}}};var c=function e(t){var n,i,a,o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a=function(e){return new Promise((function(t,n){l(e,o.options,t,n).catch((function(e){n(e)}))}))},(i="resizeImage")in(n=this)?Object.defineProperty(n,i,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[i]=a,t.sizeLimit=t.sizeLimit||r.sizeLimit,t.maxWidth=t.maxWidth||r.maxWidth,t.maxHeight=t.maxHeight||r.maxHeight,t.quality=t.quality||r.quality,t.base64OutputType=t.base64OutputType||r.base64OutputType,t.blobOutputType=t.blobOutputType||r.blobOutputType,t.allowedFileTypes=t.allowedFileTypes||r.allowedFileTypes,this.options=t}}]); //# sourceMappingURL=transform-image-js.min.map \ No newline at end of file diff --git a/lib/transform-image-js.min.map b/lib/transform-image-js.min.map index 2e38fa7..268123c 100644 --- a/lib/transform-image-js.min.map +++ b/lib/transform-image-js.min.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://transformImageJS/webpack/bootstrap","webpack://transformImageJS/./src/defaults.js","webpack://transformImageJS/./src/utils.js","webpack://transformImageJS/./src/resizeImage.js","webpack://transformImageJS/./src/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes","validateFileType","fileType","options","accepted","forEach","allowedFileType","RegExp","test","validateFileSize","imageSize","base64ToBlob","base64","regEx","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","charCodeAt","byteArray","Uint8Array","push","Blob","type","resizeImageFile","file","resolve","_reject","reader","FileReader","readAsArrayBuffer","onload","event","blob","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defaultVal","this"],"mappings":"oCACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QA0Df,OArDAF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb,EAAS,aAAc,CAAEmB,OAAO,KAQvDrB,EAAoBsB,EAAI,SAASD,EAAOE,GAEvC,GADU,EAAPA,IAAUF,EAAQrB,EAAoBqB,IAC/B,EAAPE,EAAU,OAAOF,EACpB,GAAW,EAAPE,GAA8B,iBAAVF,GAAsBA,GAASA,EAAMG,WAAY,OAAOH,EAChF,IAAII,EAAKX,OAAOY,OAAO,MAGvB,GAFA1B,EAAoBkB,EAAEO,GACtBX,OAAOC,eAAeU,EAAI,UAAW,CAAET,YAAY,EAAMK,MAAOA,IACtD,EAAPE,GAA4B,iBAATF,EAAmB,IAAI,IAAIM,KAAON,EAAOrB,EAAoBU,EAAEe,EAAIE,EAAK,SAASA,GAAO,OAAON,EAAMM,IAAQC,KAAK,KAAMD,IAC9I,OAAOF,GAIRzB,EAAoB6B,EAAI,SAAS1B,GAChC,IAAIS,EAAST,GAAUA,EAAO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GACb,OAAO,IAAIC,SAAQ,SAACxC,EAASyC,GAC3B3C,EAAgByC,EAAW,EAAKnE,QAAS4B,EAASyC,GAAlD,OAAgE,SAACC,GAC/DD,EAAOC,W,EArBQ,iB,EAAA,M,sFACnBtE,EAAQT,UAAYS,EAAQT,WAAagF,EAAWhF,UACpDS,EAAQR,SAAWQ,EAAQR,UAAY+E,EAAW/E,SAClDQ,EAAQP,UAAYO,EAAQP,WAAa8E,EAAW9E,UACpDO,EAAQN,QAAUM,EAAQN,SAAW6E,EAAW7E,QAChDM,EAAQL,iBACNK,EAAQL,kBAAoB4E,EAAW5E,iBACzCK,EAAQJ,eACNI,EAAQJ,gBAAkB2E,EAAW3E,eACvCI,EAAQH,iBACNG,EAAQH,kBAAoB0E,EAAW1E,iBACzC2E,KAAKxE,QAAUA","file":"transform-image-js.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.5,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://transformImageJS/webpack/bootstrap","webpack://transformImageJS/./src/defaults.js","webpack://transformImageJS/./src/utils.js","webpack://transformImageJS/./src/resizeImage.js","webpack://transformImageJS/./src/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","sizeLimit","maxWidth","maxHeight","quality","base64OutputType","blobOutputType","allowedFileTypes","validateFileType","fileType","options","accepted","forEach","allowedFileType","RegExp","test","validateFileSize","imageSize","base64ToBlob","base64","regEx","replace","byteCharacters","atob","byteArrays","offset","length","slice","byteNumbers","Array","charCodeAt","byteArray","Uint8Array","push","Blob","type","resizeImageFile","file","resolve","_reject","reader","FileReader","readAsArrayBuffer","onload","event","blob","target","result","size","window","URL","webkitURL","blobURL","createObjectURL","image","Image","src","resizedImage","resizeImageCanvas","output","img","canvas","document","createElement","width","height","Math","round","getContext","drawImage","toDataURL","metadata","originalHeight","originalWidth","resizedHeight","resizedWidth","TransformImage","imageFile","Promise","reject","e","defaultVal","this"],"mappings":"oCACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QA0Df,OArDAF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OAAOC,eAAeb,EAASS,EAAM,CAAEK,YAAY,EAAMC,IAAKL,KAKhEZ,EAAoBkB,EAAI,SAAShB,GACX,oBAAXiB,QAA0BA,OAAOC,aAC1CN,OAAOC,eAAeb,EAASiB,OAAOC,YAAa,CAAEC,MAAO,WAE7DP,OAAOC,eAAeb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ACZC,EAASL,EAAIK,OAqBjB,OAlBID,EAAQC,EACND,EAAQtD,EAAQR,WAClB+D,EAASC,KAAKC,MAAOF,GAAUvD,EAAQR,SAAW8D,GAClDA,EAAQtD,EAAQR,UAGd+D,EAASvD,EAAQP,YACnB6D,EAAQE,KAAKC,MAAOH,GAAStD,EAAQP,UAAY8D,GACjDA,EAASvD,EAAQP,WAKrB0D,EAAOG,MAAQA,EACfH,EAAOI,OAASA,EACJJ,EAAOO,WAAW,MAC1BC,UAAUT,EAAK,EAAG,EAAGI,EAAOC,GAEzB,CACLN,OAAQE,EAAOS,UAAU7D,EAAUC,EAAQN,SAC3CmE,SAAU,CACRC,eAAgBZ,EAAIK,OACpBQ,cAAeb,EAAII,MACnBU,cAAeT,EACfU,aAAcX,K,IC/BLY,EA3Bb,WAAYlE,GAAS,I,MAAA,Q,4FAAA,S,EAkBP,SAACmE,GACb,OAAO,IAAIC,SAAQ,SAACxC,EAASyC,GAC3B3C,EAAgByC,EAAW,EAAKnE,QAAS4B,EAASyC,GAAlD,OAAgE,SAACC,GAC/DD,EAAOC,W,EArBQ,iB,EAAA,M,sFACnBtE,EAAQT,UAAYS,EAAQT,WAAagF,EAAWhF,UACpDS,EAAQR,SAAWQ,EAAQR,UAAY+E,EAAW/E,SAClDQ,EAAQP,UAAYO,EAAQP,WAAa8E,EAAW9E,UACpDO,EAAQN,QAAUM,EAAQN,SAAW6E,EAAW7E,QAChDM,EAAQL,iBACNK,EAAQL,kBAAoB4E,EAAW5E,iBACzCK,EAAQJ,eACNI,EAAQJ,gBAAkB2E,EAAW3E,eACvCI,EAAQH,iBACNG,EAAQH,kBAAoB0E,EAAW1E,iBACzC2E,KAAKxE,QAAUA","file":"transform-image-js.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n","export default {\n sizeLimit: 16777216, // 16MB\n maxWidth: 500,\n maxHeight: 500,\n quality: 0.92,\n base64OutputType: false,\n blobOutputType: true,\n allowedFileTypes: [\"jpg\", \"png\", \"jpeg\"],\n};\n","export const validateFileType = (fileType, options) => {\n let accepted = false;\n options.allowedFileTypes.forEach((allowedFileType) => {\n const regEx = new RegExp(\"image/\" + allowedFileType);\n if (regEx.test(fileType)) accepted = true;\n });\n return accepted;\n};\n\nexport const validateFileSize = (imageSize, options) => {\n if (imageSize > options.sizeLimit) {\n throw (\n \"Please upload an image of size less than \" +\n options.sizeLimit / (1024 * 1024) +\n \"MB\"\n );\n }\n};\n\nexport const base64ToBlob = (base64, fileType) => {\n const sliceSize = 512; // uses 512 as packet size for efficient conversion\n const regEx = new RegExp(\"^data:\" + fileType + \";base64,\");\n base64 = base64.replace(regEx, \"\");\n const byteCharacters = atob(base64);\n const byteArrays = [];\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize);\n\n const byteNumbers = new Array(slice.length);\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i);\n }\n\n const byteArray = new Uint8Array(byteNumbers);\n\n byteArrays.push(byteArray);\n }\n\n const blob = new Blob(byteArrays, { type: fileType });\n return blob;\n};\n","import { validateFileType, validateFileSize, base64ToBlob } from \"./utils\";\n\n// Returns a promise\nexport const resizeImageFile = async (file, options, resolve, _reject) => {\n // Perform a null check on file\n if (!file) return;\n\n // Validate the file type\n if (!validateFileType(file.type, options)) {\n throw \"File \" + file.name + \" is not a supported image.\";\n }\n\n // read the files\n const reader = new FileReader();\n\n reader.readAsArrayBuffer(file);\n\n reader.onload = (event) => {\n const blob = new Blob([event.target.result]); // create blob...\n const imageSize = blob.size;\n\n validateFileSize(imageSize, options);\n\n window.URL = window.URL || window.webkitURL;\n const blobURL = window.URL.createObjectURL(blob); // and get it's URL\n\n // helper Image object\n const image = new Image();\n image.src = blobURL;\n image.onload = function () {\n // have to wait till it's loaded\n const resizedImage = resizeImageCanvas(image, file.type, options); // send it to canvas\n if (options.base64OutputType) {\n resolve(resizedImage);\n } else if (options.blobOutputType) {\n resizedImage.output = base64ToBlob(resizedImage.output, file.type);\n resolve(resizedImage);\n }\n };\n };\n};\n\nexport const resizeImageCanvas = (img, fileType, options) => {\n const canvas = document.createElement(\"canvas\");\n let width = img.width;\n let height = img.height;\n\n // calculate the width and height, constraining the proportions\n if (width > height) {\n if (width > options.maxWidth) {\n height = Math.round((height *= options.maxWidth / width));\n width = options.maxWidth;\n }\n } else {\n if (height > options.maxHeight) {\n width = Math.round((width *= options.maxHeight / height));\n height = options.maxHeight;\n }\n }\n\n // resize the canvas and draw the image data into it\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext(\"2d\");\n ctx.drawImage(img, 0, 0, width, height);\n\n return {\n output: canvas.toDataURL(fileType, options.quality),\n metadata: {\n originalHeight: img.height,\n originalWidth: img.width,\n resizedHeight: height,\n resizedWidth: width,\n },\n };\n};\n","import defaultVal from \"./defaults\";\nimport { resizeImageFile } from \"./resizeImage\";\n\nclass TransformImage {\n /*\n Options - An object with following properties\n sizeLimit : the byte size limit for the output file\n maxWidth: the max width for the file in px\n maxHeight: the max height for the file in px\n quality: a value between 0 and 1 to denote the quality of the output image\n base64OutputType: boolean to return a base64 string as the output\n blobOutputType: boolean to return a blob as output\n allowedFileTypes: allowed types for the image file e.g. PNG, JPEG, JPG\n */\n constructor(options) {\n options.sizeLimit = options.sizeLimit || defaultVal.sizeLimit;\n options.maxWidth = options.maxWidth || defaultVal.maxWidth;\n options.maxHeight = options.maxHeight || defaultVal.maxHeight;\n options.quality = options.quality || defaultVal.quality; // Quality - A value between 0 and 1 to denote the quality of the image in the output\n options.base64OutputType =\n options.base64OutputType || defaultVal.base64OutputType; // return Base64 string\n options.blobOutputType =\n options.blobOutputType || defaultVal.blobOutputType; // return Blob // NOTE: you can only choose one of the base64 or blob options\n options.allowedFileTypes =\n options.allowedFileTypes || defaultVal.allowedFileTypes; // An array of allowed file types\n this.options = options;\n }\n\n /*\n @params\n imageFile - The image file object obtained after user has uploaded the file\n */\n resizeImage = (imageFile) => {\n return new Promise((resolve, reject) => {\n resizeImageFile(imageFile, this.options, resolve, reject).catch((e) => {\n reject(e);\n });\n });\n };\n}\n\nexport default TransformImage;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/package.json b/package.json index 9f7538d..7217ce9 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ }, "files": [ "dist", - "lib" + "lib", + "jquery_plugin" ], "repository": { "type": "git",