apps-sdk 1.0.142 → 1.0.143

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.142",
3
+ "version": "1.0.143",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -18,6 +18,7 @@
18
18
  "expo-constants": "~15.4.6",
19
19
  "expo-device": "~5.9.4",
20
20
  "expo-file-system": "~16.0.9",
21
+ "expo-image-manipulator": "^13.0.6",
21
22
  "expo-image-picker": "^16.0.3",
22
23
  "expo-linking": "^6.2.2",
23
24
  "expo-localization": "~14.8.4",
@@ -8,6 +8,7 @@ import utils from "./Utils";
8
8
  import * as config from "../../config";
9
9
  import * as ImagePicker from 'expo-image-picker';
10
10
  import {Linking, Alert} from "react-native";
11
+ import { ImageManipulator, SaveFormat } from 'expo-image-manipulator';
11
12
 
12
13
 
13
14
  const CREATIONS_DIR = `${FileSystem.documentDirectory}/creations`
@@ -351,6 +352,35 @@ class Storage {
351
352
  }
352
353
  await Linking.openURL('app-settings:');
353
354
  }
355
+
356
+ async compressImage(imageUri, maxSizeMB = 5) {
357
+ try {
358
+ const qualities = [0.8, 0.6, 0.4, 0.2];
359
+ for (const quality of qualities) {
360
+ const context = ImageManipulator.manipulate(imageUri);
361
+ const image = await context.renderAsync();
362
+ const compressed = await image.saveAsync({ compress: quality, format: SaveFormat.JPEG });
363
+ const fileSize = await this.getFileSize(compressed.uri);
364
+ if (fileSize < maxSizeMB) {
365
+ return compressed.uri;
366
+ }
367
+ }
368
+ return null;
369
+ } catch (error) {
370
+ console.error('Error compressing image:', error);
371
+ return null;
372
+ }
373
+ }
374
+
375
+ async getFileSize(uri) {
376
+ try {
377
+ const file = await FileSystem.getInfoAsync(uri);
378
+ return file.exists ? file.size / 1024 / 1024 : 0;
379
+ } catch (error) {
380
+ console.error('Error getting file size:', error);
381
+ return 0;
382
+ }
383
+ };
354
384
  }
355
385
 
356
386
  export default new Storage();
package/types/index.d.ts CHANGED
@@ -108,6 +108,7 @@ declare module 'apps-sdk' {
108
108
  selectImageFromGallery(galleryNotGrantedTitle: string, galleryNotGrantedMessage: string, cancelText:string, openSettingsText:string): Promise<string>;
109
109
  removeAllKeys(): Promise<void>;
110
110
  deleteTempFiles(): Promise<void>;
111
+ compressImage(imageURI: string, maxSizeMB: number): Promise<string>;
111
112
  }
112
113
 
113
114
  export class Utils {