mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-18 12:41:54 -04:00
* (lint) MOB-1063 enforce trailing commas * autofix trailing commas * manually fix newly introduced maxlen violations * add trailing comma convention to i18n build
44 lines
943 B
TypeScript
44 lines
943 B
TypeScript
import ImageResizer from "@bam.tech/react-native-image-resizer";
|
|
|
|
const resizeImage = async (
|
|
pathOrUri: string,
|
|
options: {
|
|
width: number;
|
|
height?: number;
|
|
rotation?: number;
|
|
outputPath?: string;
|
|
imageOptions?: {
|
|
mode?: string;
|
|
onlyScaleDown?: boolean;
|
|
};
|
|
},
|
|
): Promise<string> => {
|
|
const {
|
|
width,
|
|
height,
|
|
rotation,
|
|
outputPath,
|
|
imageOptions,
|
|
} = options;
|
|
|
|
// Note that the default behavior of this library is to resize to contain,
|
|
// i.e. it will not adjust aspect ratio
|
|
const resizedPhoto = await ImageResizer.createResizedImage(
|
|
pathOrUri,
|
|
width, // maxWidth
|
|
height || width, // maxHeight
|
|
"JPEG", // compressFormat
|
|
100, // quality
|
|
rotation || 0, // rotation
|
|
outputPath, // outputPath
|
|
true, // keep metadata,
|
|
imageOptions, // mode and scale options
|
|
);
|
|
|
|
const { uri } = resizedPhoto;
|
|
|
|
return uri;
|
|
};
|
|
|
|
export default resizeImage;
|