Browse Source

introduced RAW image format and ZIP-base64 result packaging algorithm

Oleksandr Kucherenko 6 years ago
parent
commit
f8af243189
2 changed files with 12 additions and 9 deletions
  1. 4
    3
      src/index.d.ts
  2. 8
    6
      src/index.js

+ 4
- 3
src/index.d.ts View File

23
          */
23
          */
24
         height?: number;
24
         height?: number;
25
         /**
25
         /**
26
-         * either png or jpg or webm (Android). Defaults to png.
26
+         * either png or jpg or webm (Android). Defaults to png. raw is a ARGB array of image pixels.
27
          */
27
          */
28
-        format?: 'jpg' | 'png' | 'webm';
28
+        format?: 'jpg' | 'png' | 'webm' | 'raw';
29
         /**
29
         /**
30
          * the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg)
30
          * the quality. 0.0 - 1.0 (default). (only available on lossy formats like jpg)
31
          */
31
          */
36
          " - base64": encode as base64 and returns the raw string. Use only with small images as this may result of
36
          " - base64": encode as base64 and returns the raw string. Use only with small images as this may result of
37
          *   lags (the string is sent over the bridge). N.B. This is not a data uri, use data-uri instead.
37
          *   lags (the string is sent over the bridge). N.B. This is not a data uri, use data-uri instead.
38
          " - data-uri": same as base64 but also includes the Data URI scheme header.
38
          " - data-uri": same as base64 but also includes the Data URI scheme header.
39
+         " - zip-base64: compress data with zip deflate algorithm and than convert to base64 and return as a raw string."
39
          */
40
          */
40
-        result?: 'tmpfile' | 'base64' | 'data-uri';
41
+        result?: 'tmpfile' | 'base64' | 'data-uri' | 'zip-base64';
41
         /**
42
         /**
42
          * if true and when view is a ScrollView, the "content container" height will be evaluated instead of the
43
          * if true and when view is a ScrollView, the "content container" height will be evaluated instead of the
43
          * container height.
44
          * container height.

+ 8
- 6
src/index.js View File

8
 type Options = {
8
 type Options = {
9
   width?: number,
9
   width?: number,
10
   height?: number,
10
   height?: number,
11
-  format: "png" | "jpg" | "webm",
11
+  format: "png" | "jpg" | "webm" | "raw",
12
   quality: number,
12
   quality: number,
13
-  result: "tmpfile" | "base64" | "data-uri",
13
+  result: "tmpfile" | "base64" | "data-uri" | "zip-base64",
14
   snapshotContentContainer: boolean
14
   snapshotContentContainer: boolean
15
 };
15
 };
16
 
16
 
21
 }
21
 }
22
 
22
 
23
 const acceptedFormats = ["png", "jpg"].concat(
23
 const acceptedFormats = ["png", "jpg"].concat(
24
-  Platform.OS === "android" ? ["webm"] : []
24
+  Platform.OS === "android" ? ["webm", "raw"] : []
25
 );
25
 );
26
 
26
 
27
-const acceptedResults = ["tmpfile", "base64", "data-uri"];
27
+const acceptedResults = ["tmpfile", "base64", "data-uri"].concat(
28
+  Platform.OS === "android" ? ["zip-base64"] : []
29
+);
28
 
30
 
29
 const defaultOptions = {
31
 const defaultOptions = {
30
   format: "png",
32
   format: "png",
70
   if (acceptedFormats.indexOf(options.format) === -1) {
72
   if (acceptedFormats.indexOf(options.format) === -1) {
71
     options.format = defaultOptions.format;
73
     options.format = defaultOptions.format;
72
     errors.push(
74
     errors.push(
73
-      "option format is not in valid formats: " + acceptedFormats.join(" | ")
75
+      "option format '" + options.format + "' is not in valid formats: " + acceptedFormats.join(" | ")
74
     );
76
     );
75
   }
77
   }
76
   if (acceptedResults.indexOf(options.result) === -1) {
78
   if (acceptedResults.indexOf(options.result) === -1) {
77
     options.result = defaultOptions.result;
79
     options.result = defaultOptions.result;
78
     errors.push(
80
     errors.push(
79
-      "option result is not in valid formats: " + acceptedResults.join(" | ")
81
+      "option result '" + options.result  + "' is not in valid formats: " + acceptedResults.join(" | ")
80
     );
82
     );
81
   }
83
   }
82
   return { options, errors };
84
   return { options, errors };