Changing crop updates and disables resize processor

This commit is contained in:
Jason Miller
2020-12-09 11:48:10 -05:00
parent e3b053db12
commit 213028cfdd

View File

@@ -11,6 +11,7 @@ import {
canDecodeImageType, canDecodeImageType,
abortable, abortable,
assertSignal, assertSignal,
shallowEqual,
} from '../util'; } from '../util';
import { import {
PreprocessorState, PreprocessorState,
@@ -447,19 +448,33 @@ export default class Compress extends Component<Props, State> {
const newRotate = preprocessorState.rotate.rotate; const newRotate = preprocessorState.rotate.rotate;
const orientationChanged = oldRotate % 180 !== newRotate % 180; const orientationChanged = oldRotate % 180 !== newRotate % 180;
const { crop } = preprocessorState;
const cropChanged = !shallowEqual(crop, this.state.preprocessorState.crop);
this.setState((state) => ({ this.setState((state) => ({
loading: true, loading: true,
preprocessorState, preprocessorState,
// Flip resize values if orientation has changed // Flip resize values if orientation has changed
sides: !orientationChanged sides:
!orientationChanged && !cropChanged
? state.sides ? state.sides
: (state.sides.map((side) => { : (state.sides.map((side) => {
const currentResizeSettings = const currentResizeSettings =
side.latestSettings.processorState.resize; side.latestSettings.processorState.resize;
const resizeSettings: Partial<ProcessorState['resize']> = { let resizeSettings: Partial<ProcessorState['resize']>;
if (cropChanged) {
const img = state.source?.decoded;
resizeSettings = {
enabled: false,
width: img ? img.width - crop.left - crop.right : undefined,
height: img ? img.height - crop.top - crop.bottom : undefined,
};
} else {
resizeSettings = {
width: currentResizeSettings.height, width: currentResizeSettings.height,
height: currentResizeSettings.width, height: currentResizeSettings.width,
}; };
}
return cleanMerge( return cleanMerge(
side, side,
'latestSettings.processorState.resize', 'latestSettings.processorState.resize',