@umituz/react-native-ai-generation-content 1.83.76 → 1.83.77

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": "@umituz/react-native-ai-generation-content",
3
- "version": "1.83.76",
3
+ "version": "1.83.77",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * Photo Extraction Utilities
3
3
  * Shared photo extraction logic for wizard strategies
4
+ *
5
+ * Resize strategy:
6
+ * - Small images (<300px): scale UP to 300px minimum (AI provider requirement)
7
+ * - Large images (>1536px): scale DOWN to 1536px maximum (reduces upload size ~10x)
8
+ * - Normal images: pass through unchanged
4
9
  */
5
10
 
6
11
  import { readFileAsBase64 } from "@umituz/react-native-design-system/filesystem";
@@ -10,6 +15,7 @@ import { PHOTO_KEY_PREFIX } from "../wizard-strategy.constants";
10
15
 
11
16
 
12
17
  const MIN_IMAGE_DIMENSION = 300;
18
+ const MAX_IMAGE_DIMENSION = 1536;
13
19
 
14
20
  /**
15
21
  * Get image dimensions from URI
@@ -21,23 +27,39 @@ function getImageSize(uri: string): Promise<{ width: number; height: number }> {
21
27
  }
22
28
 
23
29
  /**
24
- * Ensure image meets minimum dimensions (300x300) required by AI providers.
25
- * Returns the original URI if already large enough, or a resized URI.
30
+ * Ensure image is within optimal dimensions for AI generation.
31
+ * - Too small (<300px): scale up (AI providers require minimum dimensions)
32
+ * - Too large (>1536px): scale down (reduces upload size, prevents timeouts)
33
+ * - Within range: return as-is
26
34
  */
27
- async function ensureMinimumSize(uri: string): Promise<string> {
35
+ async function ensureOptimalSize(uri: string): Promise<string> {
28
36
  try {
29
37
  const { width, height } = await getImageSize(uri);
38
+ const maxDim = Math.max(width, height);
30
39
 
31
- if (width >= MIN_IMAGE_DIMENSION && height >= MIN_IMAGE_DIMENSION) {
40
+ // Already within optimal range
41
+ if (width >= MIN_IMAGE_DIMENSION && height >= MIN_IMAGE_DIMENSION && maxDim <= MAX_IMAGE_DIMENSION) {
32
42
  return uri;
33
43
  }
34
44
 
35
- const scale = Math.max(MIN_IMAGE_DIMENSION / width, MIN_IMAGE_DIMENSION / height);
36
- const newWidth = Math.ceil(width * scale);
37
- const newHeight = Math.ceil(height * scale);
45
+ let newWidth: number;
46
+ let newHeight: number;
47
+
48
+ if (maxDim > MAX_IMAGE_DIMENSION) {
49
+ // Scale DOWN — largest dimension becomes MAX_IMAGE_DIMENSION
50
+ const scale = MAX_IMAGE_DIMENSION / maxDim;
51
+ newWidth = Math.round(width * scale);
52
+ newHeight = Math.round(height * scale);
53
+ } else {
54
+ // Scale UP — smallest dimension becomes MIN_IMAGE_DIMENSION
55
+ const scale = Math.max(MIN_IMAGE_DIMENSION / width, MIN_IMAGE_DIMENSION / height);
56
+ newWidth = Math.ceil(width * scale);
57
+ newHeight = Math.ceil(height * scale);
58
+ }
38
59
 
39
60
  if (typeof __DEV__ !== "undefined" && __DEV__) {
40
- console.log("[PhotoExtraction] Resizing small image", {
61
+ const direction = maxDim > MAX_IMAGE_DIMENSION ? "down" : "up";
62
+ console.log(`[PhotoExtraction] Resizing ${direction}`, {
41
63
  from: `${width}x${height}`,
42
64
  to: `${newWidth}x${newHeight}`,
43
65
  });
@@ -45,7 +67,7 @@ async function ensureMinimumSize(uri: string): Promise<string> {
45
67
 
46
68
  const result = await manipulateAsync(uri, [{ resize: { width: newWidth, height: newHeight } }], {
47
69
  format: SaveFormat.JPEG,
48
- compress: 0.9,
70
+ compress: maxDim > MAX_IMAGE_DIMENSION ? 0.8 : 0.9,
49
71
  });
50
72
 
51
73
  return result.uri;
@@ -105,8 +127,8 @@ export async function extractPhotosAsBase64(
105
127
  const results = await Promise.allSettled(
106
128
  photoUris.map(async (uri, index) => {
107
129
  try {
108
- const resizedUri = await ensureMinimumSize(uri);
109
- return await readFileAsBase64(resizedUri);
130
+ const optimizedUri = await ensureOptimalSize(uri);
131
+ return await readFileAsBase64(optimizedUri);
110
132
  } catch (error) {
111
133
  if (typeof __DEV__ !== "undefined" && __DEV__) {
112
134
  console.error(`[PhotoExtraction] Failed to read photo ${index}:`, error);
@@ -111,6 +111,7 @@ export const GenericPhotoUploadScreen: React.FC<PhotoUploadScreenProps> = ({
111
111
  { key: "photoUpload.tips.goodLighting", icon: "sunny-outline" },
112
112
  { key: "photoUpload.tips.recentPhoto", icon: "time-outline" },
113
113
  { key: "photoUpload.tips.noFilters", icon: "image-outline" },
114
+ { key: "photoUpload.tips.useWifi", icon: "wifi-outline" },
114
115
  ];
115
116
  return tipKeys.map(({ key, icon }) => ({ text: t(key), icon }));
116
117
  }, [t]);