@uppy/thumbnail-generator
Advanced tools
Comparing version 1.5.10 to 1.5.11
@@ -18,5 +18,6 @@ var _class, _temp; | ||
var ORIENTATIONS = require('./image-orientations'); | ||
var MathLog2 = require('math-log2'); // Polyfill for IE. | ||
var exifr = require('exifr/dist/mini.legacy.umd.cjs'); | ||
var exifr = require('exifr/dist/mini.legacy.umd.js'); | ||
/** | ||
@@ -27,5 +28,3 @@ * The Thumbnail Generator plugin | ||
module.exports = (_temp = _class = | ||
/*#__PURE__*/ | ||
function (_Plugin) { | ||
module.exports = (_temp = _class = /*#__PURE__*/function (_Plugin) { | ||
_inheritsLoose(ThumbnailGenerator, _Plugin); | ||
@@ -166,3 +165,3 @@ | ||
}); | ||
var orientationPromise = exifr.orientation(file.data).catch(function (_err) { | ||
var orientationPromise = exifr.rotation(file.data).catch(function (_err) { | ||
return 1; | ||
@@ -172,6 +171,5 @@ }); | ||
var image = _ref[0], | ||
rawOrientation = _ref[1]; | ||
var orientation = ORIENTATIONS[rawOrientation || 1]; | ||
orientation = _ref[1]; | ||
var dimensions = _this2.getProportionalDimensions(image, targetWidth, targetHeight, orientation.rotation); | ||
var dimensions = _this2.getProportionalDimensions(image, targetWidth, targetHeight, orientation.deg); | ||
@@ -267,7 +265,5 @@ var rotatedImage = _this2.rotateImage(image, orientation); | ||
// https://blog.uploadcare.com/image-resize-in-browsers-is-broken-e38eed08df01 | ||
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 | ||
image = this.protect(image); | ||
var steps = Math.ceil(MathLog2(image.width / targetWidth)); | ||
var steps = Math.ceil(Math.log(image.width / targetWidth) * Math.LOG2E); | ||
if (steps < 1) { | ||
@@ -298,3 +294,3 @@ steps = 1; | ||
if (translate.rotation === 90 || translate.rotation === 270) { | ||
if (translate.deg === 90 || translate.deg === 270) { | ||
w = image.height; | ||
@@ -309,4 +305,8 @@ h = image.width; | ||
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); | ||
@@ -434,2 +434,2 @@ return canvas; | ||
return ThumbnailGenerator; | ||
}(Plugin), _class.VERSION = "1.5.10", _temp); | ||
}(Plugin), _class.VERSION = "1.5.11", _temp); |
{ | ||
"name": "@uppy/thumbnail-generator", | ||
"description": "Uppy plugin that generates small previews of images to show on your upload UI.", | ||
"version": "1.5.10", | ||
"version": "1.5.11", | ||
"license": "MIT", | ||
@@ -25,4 +25,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@uppy/utils": "^2.4.2", | ||
"exifr": "^4.3.4" | ||
"@uppy/utils": "^2.4.3", | ||
"exifr": "^5.0.1", | ||
"math-log2": "^1.0.1" | ||
}, | ||
@@ -32,3 +33,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "323233488f4abe33f0fda037673d38777f109f6f" | ||
"gitHead": "6e2dfd7c0f54f38672894eac2333310dcd276c03" | ||
} |
@@ -6,4 +6,4 @@ const { Plugin } = require('@uppy/core') | ||
const isPreviewSupported = require('@uppy/utils/lib/isPreviewSupported') | ||
const ORIENTATIONS = require('./image-orientations') | ||
const exifr = require('exifr/dist/mini.legacy.umd.cjs') | ||
const MathLog2 = require('math-log2') // Polyfill for IE. | ||
const exifr = require('exifr/dist/mini.legacy.umd.js') | ||
@@ -78,8 +78,7 @@ /** | ||
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) | ||
@@ -170,5 +169,3 @@ const resizedImage = this.resizeImage(rotatedImage, dimensions.width, dimensions.height) | ||
// 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) { | ||
@@ -199,3 +196,3 @@ steps = 1 | ||
if (translate.rotation === 90 || translate.rotation === 270) { | ||
if (translate.deg === 90 || translate.deg === 270) { | ||
w = image.height | ||
@@ -211,4 +208,6 @@ h = image.width | ||
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) | ||
@@ -215,0 +214,0 @@ |
@@ -523,36 +523,2 @@ const ThumbnailGeneratorPlugin = require('./index') | ||
}) | ||
describe('rotateImage', () => { | ||
it.each([ | ||
[0, { width: 100, height: 80 }], | ||
[90, { width: 80, height: 100 }], | ||
[180, { width: 100, height: 80 }], | ||
[270, { width: 80, height: 100 }]])( | ||
'should rotate image with %i degree', (rotation, expectedSize) => { | ||
const core = new MockCore() | ||
const plugin = new ThumbnailGeneratorPlugin(core) | ||
const image = { | ||
width: 100, | ||
height: 80 | ||
} | ||
const context = { | ||
drawImage: jest.fn(), | ||
translate: jest.fn(), | ||
rotate: jest.fn(), | ||
scale: jest.fn() | ||
} | ||
const canvas = { | ||
width: 0, | ||
height: 0, | ||
getContext: jest.fn().mockReturnValue(context) | ||
} | ||
document.createElement = jest.fn().mockReturnValue(canvas) | ||
const result = plugin.rotateImage(image, { rotation: rotation }) | ||
expect(result).toEqual({ | ||
...expectedSize, | ||
getContext: canvas.getContext | ||
}) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43937
4
10
1136
+ Addedmath-log2@^1.0.1
+ Addedexifr@5.0.6(transitive)
+ Addedmath-log2@1.0.1(transitive)
- Removedexifr@4.3.5(transitive)
Updated@uppy/utils@^2.4.3
Updatedexifr@^5.0.1