Fix crop bounds exceeding image bounds due to EXIF rotation on Android
This commit is contained in:
@@ -249,15 +249,11 @@ export default function CameraScreen({
|
||||
// -- DOWNSCALE & CROP TO EXACTLY 3:2 --
|
||||
try {
|
||||
console.log('Manipulating image to 3:2 ratio and downscaling to prevent OOM...');
|
||||
let w = rawWidth;
|
||||
let h = rawHeight;
|
||||
|
||||
// If USB camera didn't provide width/height, read them
|
||||
if (!w || !h) {
|
||||
const info = await ImageManipulator.manipulateAsync(capturedUri, []);
|
||||
w = info.width;
|
||||
h = info.height;
|
||||
}
|
||||
// ALWAYS read true dimensions from ImageManipulator.
|
||||
// expo-camera rawWidth/rawHeight ignores EXIF rotation, causing crop bounds to exceed image bounds!
|
||||
const info = await ImageManipulator.manipulateAsync(capturedUri, []);
|
||||
let w = info.width;
|
||||
let h = info.height;
|
||||
|
||||
const actions: ImageManipulator.Action[] = [];
|
||||
const isLandscape = w >= h;
|
||||
@@ -290,10 +286,10 @@ export default function CameraScreen({
|
||||
}
|
||||
actions.push({
|
||||
crop: {
|
||||
originX: Math.round(originX),
|
||||
originY: Math.round(originY),
|
||||
width: Math.round(cropWidth),
|
||||
height: Math.round(cropHeight)
|
||||
originX: Math.max(0, Math.floor(originX)),
|
||||
originY: Math.max(0, Math.floor(originY)),
|
||||
width: Math.min(w - Math.max(0, Math.floor(originX)), Math.floor(cropWidth)),
|
||||
height: Math.min(h - Math.max(0, Math.floor(originY)), Math.floor(cropHeight))
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -315,7 +311,7 @@ export default function CameraScreen({
|
||||
console.log('Successfully manipulated and cropped image');
|
||||
} catch (manipError) {
|
||||
console.error('Failed to manipulate image, preventing OOM crash!', manipError);
|
||||
alert('Fehler bei der Bildverarbeitung! Das Bild ist zu groß oder das Format wird nicht unterstützt.');
|
||||
alert('Bildverarbeitungs-Fehler: ' + (manipError.message || manipError.toString()));
|
||||
onCancel();
|
||||
return; // Abort here so we don't send a 16MB raw image to PreviewScreen
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user