aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-09-08 16:08:48 -0400
committerbobzel <zzzman@gmail.com>2020-09-08 16:08:48 -0400
commit39224bee728cd17861d17d0d20f62a92aadf3090 (patch)
tree3e83e7cc334a89c9ab0b5b2a7368fc5528b8c7b4 /src
parent157faac6a3c8a7c2347baf78e1796ff0aa3e0312 (diff)
fixed images with different exif orientations and simplified ImageBox
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/Documents.ts4
-rw-r--r--src/client/views/nodes/ImageBox.tsx57
2 files changed, 17 insertions, 44 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 8d1f8a04e..7e276747c 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -1226,6 +1226,10 @@ export namespace DocUtils {
proto["data-nativeOrientation"] = result.exifData?.data?.image?.Orientation;
proto["data-nativeWidth"] = (result.nativeWidth < result.nativeHeight) ? maxNativeDim * result.nativeWidth / result.nativeHeight : maxNativeDim;
proto["data-nativeHeight"] = (result.nativeWidth < result.nativeHeight) ? maxNativeDim : maxNativeDim / (result.nativeWidth / result.nativeHeight);
+ if (Number(result.exifData?.data?.image?.Orientation) >= 5) {
+ proto["data-nativeHeight"] = (result.nativeWidth < result.nativeHeight) ? maxNativeDim * result.nativeWidth / result.nativeHeight : maxNativeDim;
+ proto["data-nativeWidth"] = (result.nativeWidth < result.nativeHeight) ? maxNativeDim : maxNativeDim / (result.nativeWidth / result.nativeHeight);
+ }
proto.contentSize = result.contentSize;
}
generatedDocuments.push(doc);
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 5832a51a7..d1e7f903b 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -26,6 +26,7 @@ import { FaceRectangles } from './FaceRectangles';
import { FieldView, FieldViewProps } from './FieldView';
import "./ImageBox.scss";
import React = require("react");
+import { takeWhile } from 'lodash';
const path = require('path');
const { Howl } = require('howler');
@@ -73,10 +74,16 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps, ImageD
}
componentDidMount() {
- this._pathDisposer = reaction(() => this.paths.length && this.resize(this.paths[0]),
- () => true,
+ this._pathDisposer = reaction(() => ({ nativeSize: this.nativeSize, width: this.layoutDoc[WidthSym]() }),
+ ({ nativeSize, width }) => {
+ this.layoutDoc._nativeWidth = nativeSize.nativeWidth;
+ this.layoutDoc._nativeHeight = nativeSize.nativeHeight;
+ this.layoutDoc._nativeOrientation = nativeSize.nativeOrientation;
+ this.layoutDoc._height = width * nativeSize.nativeHeight / nativeSize.nativeWidth;
+ },
{ fireImmediately: true });
}
+
componentWillUnmount() {
this._pathDisposer?.();
}
@@ -249,45 +256,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps, ImageD
}
_curSuffix = "_m";
- resize = (imgPath: string) => {
- const basePath = imgPath.replace(/_[oms]./, "");
- const curPath = this.dataDoc[this.fieldKey + "-path"];
- const cachedNativeSize = {
- width: basePath === curPath || !curPath ? NumCast(this.dataDoc[this.fieldKey + "-nativeWidth"]) : 0,
- height: basePath === curPath || !curPath ? NumCast(this.dataDoc[this.fieldKey + "-nativeHeight"]) : 0,
- };
- const docAspect = this.layoutDoc[HeightSym]() / this.layoutDoc[WidthSym]();
- const cachedAspect = cachedNativeSize.height / cachedNativeSize.width;
- if (!cachedNativeSize.width || !cachedNativeSize.height || Math.abs(NumCast(this.layoutDoc._width) / NumCast(this.layoutDoc._height) - cachedNativeSize.width / cachedNativeSize.height) > 0.05) {
- if (!this.layoutDoc.isTemplateDoc || this.dataDoc !== this.layoutDoc) {
- const rotation = NumCast(this.dataDoc[this.fieldKey + "-rotation"]) % 180;
- const orientation = NumCast(this.dataDoc[this.fieldKey + "-nativeOrientation"]);
- if (orientation >= 5 || rotation === 90 || rotation === 270) {
- this.layoutDoc._nativeWidth = NumCast(this.dataDoc[this.fieldKey + "-nativeHeight"]);
- this.layoutDoc._nativeHeight = NumCast(this.dataDoc[this.fieldKey + "-nativeWidth"]);
- } else {
- this.layoutDoc._nativeWidth = NumCast(this.dataDoc[this.fieldKey + "-nativeWidth"]);
- this.layoutDoc._nativeHeight = NumCast(this.dataDoc[this.fieldKey + "-nativeHeight"]);
- }
- const rotatedAspect = NumCast(this.layoutDoc._nativeHeight) / NumCast(this.layoutDoc._nativeWidth);
- if (this.layoutDoc[WidthSym]() && (!cachedNativeSize.width || !cachedNativeSize.height || Math.abs(1 - docAspect / rotatedAspect) > 0.1)) {
- this.layoutDoc._height = this.layoutDoc[WidthSym]() * rotatedAspect;
- this.dataDoc[this.fieldKey + "-path"] = basePath;
- }
- } else if (Math.abs(1 - docAspect / cachedAspect) > 0.1) {
- this.layoutDoc._width = this.layoutDoc[WidthSym]() || cachedNativeSize.width;
- this.layoutDoc._height = this.layoutDoc[WidthSym]() * cachedAspect;
- }
- } else if (this.layoutDoc._nativeWidth !== cachedNativeSize.width || this.layoutDoc._nativeHeight !== cachedNativeSize.height) {
- !(this.layoutDoc[StrCast(this.layoutDoc.layoutKey)] instanceof Doc) && setTimeout(() => {
- if (!(this.layoutDoc[StrCast(this.layoutDoc.layoutKey)] instanceof Doc)) {
- this.layoutDoc._nativeWidth = cachedNativeSize.width;
- this.layoutDoc._nativeHeight = cachedNativeSize.height;
- }
- }, 0);
- }
- }
-
@action
onPointerEnter = () => {
const self = this;
@@ -370,7 +338,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps, ImageD
const pw = this.props.PanelWidth?.() || 50;
const nativeWidth = NumCast(this.dataDoc[this.fieldKey + "-nativeWidth"], pw);
const nativeHeight = NumCast(this.dataDoc[this.fieldKey + "-nativeHeight"], 1);
- return { nativeWidth, nativeHeight };
+ const nativeOrientation = NumCast(this.dataDoc[this.fieldKey + "-nativeOrientation"], 1);
+ return { nativeWidth, nativeHeight, nativeOrientation };
}
// this._curSuffix = "";
@@ -391,9 +360,9 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps, ImageD
const srcpath = this.paths[0];
const fadepath = this.paths[Math.min(1, this.paths.length - 1)];
- const { nativeWidth, nativeHeight } = this.nativeSize;
+ const { nativeWidth, nativeHeight, nativeOrientation } = this.nativeSize;
const rotation = NumCast(this.dataDoc[this.fieldKey + "-rotation"]);
- const aspect = (rotation % 180) ? nativeHeight / nativeWidth : 1;
+ const aspect = rotation % 180 ? nativeHeight / nativeWidth : 1;
let transformOrigin = "center center";
let transform = `translate(0%, 0%) rotate(${rotation}deg) scale(${aspect})`;
if (rotation === 90 || rotation === -270) {