1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import ExpoImageCropTool, {type OpenCropperOptions} from 'expo-image-crop-tool'
import {type ImagePickerOptions, launchCameraAsync} from 'expo-image-picker'
export {openPicker, type PickerImage as RNImage} from './picker.shared'
export async function openCamera(customOpts: ImagePickerOptions) {
const opts: ImagePickerOptions = {
mediaTypes: 'images',
...customOpts,
}
const res = await launchCameraAsync(opts)
if (!res || !res.assets) {
throw new Error('Camera was closed before taking a photo')
}
const asset = res?.assets[0]
return {
path: asset.uri,
mime: asset.mimeType ?? 'image/jpeg',
size: asset.fileSize ?? 0,
width: asset.width,
height: asset.height,
}
}
export async function openCropper(opts: OpenCropperOptions) {
const item = await ExpoImageCropTool.openCropperAsync({
...opts,
format: 'jpeg',
})
return {
path: item.path,
mime: item.mime,
size: item.size,
width: item.width,
height: item.height,
}
}
|