|
@@ -3,7 +3,7 @@ const Translator = require('@uppy/utils/lib/Translator')
|
|
|
const dataURItoBlob = require('@uppy/utils/lib/dataURItoBlob')
|
|
|
const isObjectURL = require('@uppy/utils/lib/isObjectURL')
|
|
|
const isPreviewSupported = require('@uppy/utils/lib/isPreviewSupported')
|
|
|
-const ORIENTATIONS = require('./image-orientations')
|
|
|
+const MathLog2 = require('math-log2') // Polyfill for IE.
|
|
|
const exifr = require('exifr/dist/mini.legacy.umd.js')
|
|
|
|
|
|
/**
|
|
@@ -74,12 +74,11 @@ module.exports = class ThumbnailGenerator extends Plugin {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- const orientationPromise = exifr.orientation(file.data).catch(_err => 1)
|
|
|
+ const orientationPromise = exifr.rotation(file.data).catch(_err => 1)
|
|
|
|
|
|
return Promise.all([onload, orientationPromise])
|
|
|
- .then(([image, rawOrientation]) => {
|
|
|
- const orientation = ORIENTATIONS[rawOrientation || 1]
|
|
|
- const dimensions = this.getProportionalDimensions(image, targetWidth, targetHeight, orientation.rotation)
|
|
|
+ .then(([image, orientation]) => {
|
|
|
+ const dimensions = this.getProportionalDimensions(image, targetWidth, targetHeight, orientation.deg)
|
|
|
const rotatedImage = this.rotateImage(image, orientation)
|
|
|
const resizedImage = this.resizeImage(rotatedImage, dimensions.width, dimensions.height)
|
|
|
return this.canvasToBlob(resizedImage, 'image/png')
|
|
@@ -165,9 +164,7 @@ module.exports = class ThumbnailGenerator extends Plugin {
|
|
|
|
|
|
image = this.protect(image)
|
|
|
|
|
|
- // Use the Polyfill for Math.log2() since IE doesn't support log2
|
|
|
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2#Polyfill
|
|
|
- var steps = Math.ceil(Math.log(image.width / targetWidth) * Math.LOG2E)
|
|
|
+ var steps = Math.ceil(MathLog2(image.width / targetWidth))
|
|
|
if (steps < 1) {
|
|
|
steps = 1
|
|
|
}
|
|
@@ -193,7 +190,7 @@ module.exports = class ThumbnailGenerator extends Plugin {
|
|
|
var w = image.width
|
|
|
var h = image.height
|
|
|
|
|
|
- if (translate.rotation === 90 || translate.rotation === 270) {
|
|
|
+ if (translate.deg === 90 || translate.deg === 270) {
|
|
|
w = image.height
|
|
|
h = image.width
|
|
|
}
|
|
@@ -204,8 +201,10 @@ module.exports = class ThumbnailGenerator extends Plugin {
|
|
|
|
|
|
var context = canvas.getContext('2d')
|
|
|
context.translate(w / 2, h / 2)
|
|
|
- context.rotate(translate.rotation * Math.PI / 180)
|
|
|
- context.scale(translate.xScale, translate.yScale)
|
|
|
+ if (translate.canvas) {
|
|
|
+ context.rotate(translate.rad)
|
|
|
+ context.scale(translate.scaleX, translate.scaleY)
|
|
|
+ }
|
|
|
context.drawImage(image, -image.width / 2, -image.height / 2, image.width, image.height)
|
|
|
|
|
|
return canvas
|