Open ShaoGongBra opened 2 months ago
这是修改参考
diff --git a/node_modules/@tarojs/taro-rn/dist/lib/compressImage/index.js b/node_modules/@tarojs/taro-rn/dist/lib/compressImage/index.js
index 9549762..32838ed 100644
--- a/node_modules/@tarojs/taro-rn/dist/lib/compressImage/index.js
+++ b/node_modules/@tarojs/taro-rn/dist/lib/compressImage/index.js
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
-import ImageResizer from '@bam.tech/react-native-image-resizer';
+import { manipulateAsync, SaveFormat } from 'expo-image-manipulator';
import { Image } from 'react-native';
import { errorHandler, successHandler } from '../../utils';
/**
@@ -20,8 +20,13 @@ export function compressImage(opt) {
const res = { errMsg: 'compressImage:ok', tempFilePath: '' };
const _createResizedImage = (...args_1) => __awaiter(this, [...args_1], void 0, function* (width = 800, height = 800) {
try {
- const compressFormat = src.toLocaleLowerCase().endsWith('.png') ? 'PNG' : 'JPEG';
- const { uri } = yield ImageResizer.createResizedImage(src, width, height, compressFormat, quality);
+ const compressFormat = src.toLocaleLowerCase().endsWith('.png') ? SaveFormat.PNG : SaveFormat.JPEG;
+ const { uri } = yield manipulateAsync(src, [
+ { resize: { width, height }}
+ ], {
+ compress: quality,
+ format: compressFormat
+ });
res.tempFilePath = uri;
return successHandler(success, complete)(res);
}
相关平台
React Native
使用框架: React
复现步骤
建议可以换成expo-image-manipulator 也能实现压缩图片的功能
期望结果
1
实际结果
2
环境信息