aboutsummaryrefslogtreecommitdiff
path: root/src/utils/camera.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-07-14 14:50:17 -0400
committerGitHub <noreply@github.com>2021-07-14 14:50:17 -0400
commit4b6ada10d14e569c897fa289f57886e1daa2478d (patch)
treeb56b7ea0f94d5cba12e64c430ac8889fd495832c /src/utils/camera.ts
parent68f05afdf2d4ca29df60761c3d8f8ee445c1804d (diff)
parent1b9059d49532eacb60bf36b25771df42541670f4 (diff)
Merge pull request #502 from brian-tagg/tma955-video-cropping
[TMA-955] video cropping
Diffstat (limited to 'src/utils/camera.ts')
-rw-r--r--src/utils/camera.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/utils/camera.ts b/src/utils/camera.ts
index 4f933b0c..9e37d62e 100644
--- a/src/utils/camera.ts
+++ b/src/utils/camera.ts
@@ -8,6 +8,7 @@ import {
TakePictureOptions,
TakePictureResponse,
} from 'react-native-camera';
+import {ProcessingManager} from 'react-native-video-processing';
import ImagePicker, {ImageOrVideo, Video} from 'react-native-image-crop-picker';
import {ERROR_UPLOAD} from '../constants/strings';
@@ -116,3 +117,40 @@ export const showGIFFailureAlert = (onSuccess: () => void) =>
),
},
);
+
+export const cropVideo = (
+ sourceUri: string,
+ handleData: (data: any) => any,
+ videoCropValues?: {
+ cropWidth?: number;
+ cropHeight?: number;
+ cropOffsetX?: number;
+ cropOffsetY?: number;
+ },
+) => {
+ ProcessingManager.crop(sourceUri, {
+ cropWidth: videoCropValues
+ ? videoCropValues.cropWidth
+ ? Math.round(videoCropValues.cropWidth)
+ : 100
+ : 100,
+ cropHeight: videoCropValues
+ ? videoCropValues.cropHeight
+ ? Math.round(videoCropValues.cropHeight)
+ : 100
+ : 100,
+ cropOffsetX: videoCropValues
+ ? videoCropValues.cropOffsetX
+ ? Math.round(videoCropValues.cropOffsetX)
+ : 0
+ : 0,
+ cropOffsetY: videoCropValues
+ ? videoCropValues.cropOffsetY
+ ? Math.round(videoCropValues.cropOffsetY)
+ : 0
+ : 0,
+ quality: 'highest',
+ }).then((data: any) => {
+ handleData(data);
+ });
+};