|
@@ -135,12 +135,6 @@ function extend (...objs) {
|
|
|
|
|
|
|
|
|
|
|
|
-function getProportionalImageHeight (img, newWidth) {
|
|
|
- var aspect = img.width / img.height
|
|
|
- var newHeight = Math.round(newWidth / aspect)
|
|
|
- return newHeight
|
|
|
-}
|
|
|
-
|
|
|
function getFileType (file) {
|
|
|
return file.type ? file.type.split('/') : ['', '']
|
|
|
|
|
@@ -171,90 +165,6 @@ function getFileNameAndExtension (fullFileName) {
|
|
|
return [fileName, fileExt]
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Reads file as data URI from file object,
|
|
|
- * the one you get from input[type=file] or drag & drop.
|
|
|
- *
|
|
|
- * @param {Object} file object
|
|
|
- * @return {Promise} dataURL of the file
|
|
|
- *
|
|
|
- */
|
|
|
-function readFile (fileObj) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const reader = new FileReader()
|
|
|
- reader.addEventListener('load', function (ev) {
|
|
|
- return resolve(ev.target.result)
|
|
|
- })
|
|
|
- reader.readAsDataURL(fileObj)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
- * Resizes an image to specified width and proportional height, using canvas
|
|
|
- * See https:
|
|
|
- * http:
|
|
|
- * @TODO see if we need https:
|
|
|
- *
|
|
|
- * @param {String} Data URI of the original image
|
|
|
- * @param {String} width of the resulting image
|
|
|
- * @return {String} Data URI of the resized image
|
|
|
- */
|
|
|
-function createImageThumbnail (imgDataURI, newWidth) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- const img = new Image()
|
|
|
- img.addEventListener('load', () => {
|
|
|
- const newImageWidth = newWidth
|
|
|
- const newImageHeight = getProportionalImageHeight(img, newImageWidth)
|
|
|
-
|
|
|
-
|
|
|
- const canvas = document.createElement('canvas')
|
|
|
- const ctx = canvas.getContext('2d')
|
|
|
-
|
|
|
-
|
|
|
- canvas.width = newImageWidth
|
|
|
- canvas.height = newImageHeight
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- ctx.drawImage(img, 0, 0, newImageWidth, newImageHeight)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- const thumbnail = canvas.toDataURL('image/png')
|
|
|
- return resolve(thumbnail)
|
|
|
- })
|
|
|
- img.src = imgDataURI
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
function supportsMediaRecorder () {
|
|
|
return typeof MediaRecorder === 'function' && !!MediaRecorder.prototype &&
|
|
|
typeof MediaRecorder.prototype.start === 'function'
|
|
@@ -452,9 +362,6 @@ module.exports = {
|
|
|
|
|
|
|
|
|
extend,
|
|
|
- readFile,
|
|
|
- createImageThumbnail,
|
|
|
- getProportionalImageHeight,
|
|
|
supportsMediaRecorder,
|
|
|
isTouchDevice,
|
|
|
getFileNameAndExtension,
|