fix for rotated jpegs
This commit is contained in:
parent
800ca0cc54
commit
f017499cbf
3 changed files with 39 additions and 1 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -220,6 +220,14 @@
|
||||||
"resolved": "https://npm.stroeermediabrands.de/etag/-/etag-1.8.1.tgz",
|
"resolved": "https://npm.stroeermediabrands.de/etag/-/etag-1.8.1.tgz",
|
||||||
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
|
||||||
},
|
},
|
||||||
|
"exif": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/exif/-/exif-0.6.0.tgz",
|
||||||
|
"integrity": "sha1-YKYmaAdlQst+T1cZnUrG830sX0o=",
|
||||||
|
"requires": {
|
||||||
|
"debug": "^2.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"express": {
|
"express": {
|
||||||
"version": "4.17.1",
|
"version": "4.17.1",
|
||||||
"resolved": "https://npm.stroeermediabrands.de/express/-/express-4.17.1.tgz",
|
"resolved": "https://npm.stroeermediabrands.de/express/-/express-4.17.1.tgz",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
|
"exif": "^0.6.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"image-size": "^0.9.3",
|
"image-size": "^0.9.3",
|
||||||
"multer": "^1.4.2",
|
"multer": "^1.4.2",
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,45 @@
|
||||||
import sizeOf from 'image-size'
|
import sizeOf from 'image-size'
|
||||||
import Util from './../common/Util.js'
|
import Util from './../common/Util.js'
|
||||||
|
import exif from 'exif'
|
||||||
|
|
||||||
// cut size of each puzzle tile in the
|
// cut size of each puzzle tile in the
|
||||||
// final resized version of the puzzle image
|
// final resized version of the puzzle image
|
||||||
const TILE_SIZE = 64
|
const TILE_SIZE = 64
|
||||||
|
|
||||||
|
async function getDimensions(imagePath) {
|
||||||
|
let dimensions = sizeOf(imagePath)
|
||||||
|
try {
|
||||||
|
const orientation = await getExifOrientation(imagePath)
|
||||||
|
// when image is rotated to the left or right, switch width/height
|
||||||
|
// https://jdhao.github.io/2019/07/31/image_rotation_exif_info/
|
||||||
|
if (orientation === 6 || orientation === 8) {
|
||||||
|
return {
|
||||||
|
width: dimensions.height,
|
||||||
|
height: dimensions.width,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
return dimensions
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getExifOrientation(imagePath) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
new exif.ExifImage({ image: imagePath }, function (error, exifData) {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
resolve(exifData.image.Orientation)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function createPuzzle(targetTiles, image) {
|
async function createPuzzle(targetTiles, image) {
|
||||||
const imagePath = image.file
|
const imagePath = image.file
|
||||||
const imageUrl = image.url
|
const imageUrl = image.url
|
||||||
|
|
||||||
// load bitmap, to determine the original size of the image
|
// load bitmap, to determine the original size of the image
|
||||||
const dim = sizeOf(imagePath)
|
const dim = await getDimensions(imagePath)
|
||||||
|
|
||||||
// determine puzzle information from the bitmap
|
// determine puzzle information from the bitmap
|
||||||
const info = determinePuzzleInfo(dim.width, dim.height, targetTiles)
|
const info = determinePuzzleInfo(dim.width, dim.height, targetTiles)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue