react-native-expo-cropper 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ImageCropper.js +36 -26
- package/lib/ImageProcessor.js +5 -6
- package/package.json +1 -1
- package/src/ImageCropper.js +8 -5
- package/src/ImageProcessor.js +4 -8
package/lib/ImageCropper.js
CHANGED
|
@@ -227,52 +227,62 @@ var ImageCropper = function ImageCropper(_ref) {
|
|
|
227
227
|
style: _ImageCropperStyles["default"].buttonText
|
|
228
228
|
}, "Reset")), image && /*#__PURE__*/_react["default"].createElement(_reactNative.TouchableOpacity, {
|
|
229
229
|
style: _ImageCropperStyles["default"].button,
|
|
230
|
-
onPress: /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
231
|
-
var
|
|
232
|
-
return _regenerator().w(function (
|
|
233
|
-
while (1) switch (
|
|
230
|
+
onPress: /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
231
|
+
var capturePromise, enhancedUri, name, _t;
|
|
232
|
+
return _regenerator().w(function (_context2) {
|
|
233
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
234
234
|
case 0:
|
|
235
235
|
// setShowFullScreenCapture(true);
|
|
236
236
|
setIsLoading(true);
|
|
237
237
|
setShowResult(true);
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
_context2.p = 1;
|
|
239
|
+
_context2.n = 2;
|
|
240
240
|
return new Promise(function (resolve) {
|
|
241
241
|
return requestAnimationFrame(resolve);
|
|
242
242
|
});
|
|
243
243
|
case 2:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
244
|
+
capturePromise = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
245
|
+
var capturedUri;
|
|
246
|
+
return _regenerator().w(function (_context) {
|
|
247
|
+
while (1) switch (_context.n) {
|
|
248
|
+
case 0:
|
|
249
|
+
_context.n = 1;
|
|
250
|
+
return (0, _reactNativeViewShot.captureRef)(viewRef.current, {
|
|
251
|
+
format: 'jpg',
|
|
252
|
+
quality: 1,
|
|
253
|
+
result: 'tmpfile'
|
|
254
|
+
});
|
|
255
|
+
case 1:
|
|
256
|
+
capturedUri = _context.v;
|
|
257
|
+
return _context.a(2, (0, _ImageProcessor.enhanceImage)(capturedUri, addheight));
|
|
258
|
+
}
|
|
259
|
+
}, _callee);
|
|
260
|
+
}))();
|
|
261
|
+
_context2.n = 3;
|
|
252
262
|
return (0, _ImageProcessor.enhanceImage)(capturedUri, addheight);
|
|
253
|
-
case
|
|
254
|
-
enhancedUri =
|
|
263
|
+
case 3:
|
|
264
|
+
enhancedUri = _context2.v;
|
|
255
265
|
name = "IMAGE XTK".concat(Date.now(), ".png");
|
|
256
266
|
if (onConfirm) {
|
|
257
267
|
onConfirm(enhancedUri, name);
|
|
258
268
|
}
|
|
259
|
-
|
|
269
|
+
_context2.n = 5;
|
|
260
270
|
break;
|
|
261
|
-
case
|
|
262
|
-
|
|
263
|
-
_t =
|
|
271
|
+
case 4:
|
|
272
|
+
_context2.p = 4;
|
|
273
|
+
_t = _context2.v;
|
|
264
274
|
console.error("Erreur lors de la capture :", _t);
|
|
265
275
|
alert("Erreur lors de la capture !");
|
|
266
|
-
case
|
|
267
|
-
|
|
276
|
+
case 5:
|
|
277
|
+
_context2.p = 5;
|
|
268
278
|
setShowResult(false);
|
|
269
279
|
setIsLoading(false);
|
|
270
280
|
setShowFullScreenCapture(false);
|
|
271
|
-
return
|
|
272
|
-
case
|
|
273
|
-
return
|
|
281
|
+
return _context2.f(5);
|
|
282
|
+
case 6:
|
|
283
|
+
return _context2.a(2);
|
|
274
284
|
}
|
|
275
|
-
},
|
|
285
|
+
}, _callee2, null, [[1, 4, 5, 6]]);
|
|
276
286
|
}))
|
|
277
287
|
}, /*#__PURE__*/_react["default"].createElement(_reactNative.Text, {
|
|
278
288
|
style: _ImageCropperStyles["default"].buttonText
|
package/lib/ImageProcessor.js
CHANGED
|
@@ -13,7 +13,7 @@ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.
|
|
|
13
13
|
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
14
14
|
var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
|
|
15
15
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(uri, addheight) {
|
|
16
|
-
var imageInfo, ratio,
|
|
16
|
+
var imageInfo, ratio, maxHeight, newWidth, newHeight, result, _t;
|
|
17
17
|
return _regenerator().w(function (_context) {
|
|
18
18
|
while (1) switch (_context.p = _context.n) {
|
|
19
19
|
case 0:
|
|
@@ -23,9 +23,8 @@ var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
|
|
|
23
23
|
case 1:
|
|
24
24
|
imageInfo = _context.v;
|
|
25
25
|
ratio = imageInfo.height / imageInfo.width;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
newWidth = Math.round(targetHeight / ratio);
|
|
26
|
+
maxHeight = addheight;
|
|
27
|
+
newWidth = Math.round(maxHeight / ratio);
|
|
29
28
|
newHeight = Math.round(newWidth * ratio);
|
|
30
29
|
_context.n = 2;
|
|
31
30
|
return ImageManipulator.manipulateAsync(uri, [{
|
|
@@ -34,8 +33,8 @@ var enhanceImage = exports.enhanceImage = /*#__PURE__*/function () {
|
|
|
34
33
|
height: newHeight
|
|
35
34
|
}
|
|
36
35
|
}], {
|
|
37
|
-
compress:
|
|
38
|
-
format: ImageManipulator.SaveFormat.
|
|
36
|
+
compress: 1,
|
|
37
|
+
format: ImageManipulator.SaveFormat.PNG
|
|
39
38
|
});
|
|
40
39
|
case 2:
|
|
41
40
|
result = _context.v;
|
package/package.json
CHANGED
package/src/ImageCropper.js
CHANGED
|
@@ -188,11 +188,14 @@ const ImageCropper = ({ onConfirm, openCameraFirst, initialImage ,addheight}) =>
|
|
|
188
188
|
setShowResult(true);
|
|
189
189
|
try {
|
|
190
190
|
await new Promise((resolve) => requestAnimationFrame(resolve));
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
191
|
+
const capturePromise = (async () => {
|
|
192
|
+
const capturedUri = await captureRef(viewRef.current, {
|
|
193
|
+
format: 'jpg',
|
|
194
|
+
quality: 1,
|
|
195
|
+
result: 'tmpfile',
|
|
196
|
+
});
|
|
197
|
+
return enhanceImage(capturedUri, addheight);
|
|
198
|
+
})();
|
|
196
199
|
|
|
197
200
|
const enhancedUri = await enhanceImage(capturedUri ,addheight);
|
|
198
201
|
const name = `IMAGE XTK${Date.now()}.png`;
|
package/src/ImageProcessor.js
CHANGED
|
@@ -5,12 +5,8 @@ export const enhanceImage = async (uri , addheight) => {
|
|
|
5
5
|
const imageInfo = await ImageManipulator.manipulateAsync(uri, []);
|
|
6
6
|
const ratio = imageInfo.height / imageInfo.width;
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
? Math.min(addheight, MAX_TARGET_HEIGHT)
|
|
11
|
-
: MAX_TARGET_HEIGHT;
|
|
12
|
-
|
|
13
|
-
const newWidth = Math.round(targetHeight / ratio);
|
|
8
|
+
const maxHeight = addheight;
|
|
9
|
+
const newWidth = Math.round(maxHeight / ratio);
|
|
14
10
|
const newHeight = Math.round(newWidth * ratio);
|
|
15
11
|
|
|
16
12
|
const result = await ImageManipulator.manipulateAsync(
|
|
@@ -19,8 +15,8 @@ export const enhanceImage = async (uri , addheight) => {
|
|
|
19
15
|
{ resize: { width: newWidth, height: newHeight } },
|
|
20
16
|
],
|
|
21
17
|
{
|
|
22
|
-
compress:
|
|
23
|
-
format: ImageManipulator.SaveFormat.
|
|
18
|
+
compress: 1,
|
|
19
|
+
format: ImageManipulator.SaveFormat.PNG
|
|
24
20
|
}
|
|
25
21
|
);
|
|
26
22
|
|