@capgo/capacitor-file-compressor 7.0.0
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/CapgoCapacitorFileCompressor.podspec +17 -0
- package/LICENSE +21 -0
- package/Package.swift +28 -0
- package/README.md +136 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/io/capgo/filecompressor/FileCompressorPlugin.java +163 -0
- package/dist/docs.json +316 -0
- package/dist/esm/definitions.d.ts +263 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +9 -0
- package/dist/esm/web.js +67 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +81 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +84 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/FileCompressorPlugin/FileCompressorPlugin.swift +116 -0
- package/package.json +80 -0
package/dist/docs.json
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "FileCompressorPlugin",
|
|
4
|
+
"slug": "filecompressorplugin",
|
|
5
|
+
"docs": "Capacitor File Compressor Plugin interface for image compression.",
|
|
6
|
+
"tags": [
|
|
7
|
+
{
|
|
8
|
+
"text": "7.0.0",
|
|
9
|
+
"name": "since"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"methods": [
|
|
13
|
+
{
|
|
14
|
+
"name": "compressImage",
|
|
15
|
+
"signature": "(options: CompressImageOptions) => Promise<CompressImageResult>",
|
|
16
|
+
"parameters": [
|
|
17
|
+
{
|
|
18
|
+
"name": "options",
|
|
19
|
+
"docs": "- Configuration options for image compression",
|
|
20
|
+
"type": "CompressImageOptions"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"returns": "Promise<CompressImageResult>",
|
|
24
|
+
"tags": [
|
|
25
|
+
{
|
|
26
|
+
"name": "param",
|
|
27
|
+
"text": "options - Configuration options for image compression"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "returns",
|
|
31
|
+
"text": "Promise that resolves with the compressed image path or blob"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "throws",
|
|
35
|
+
"text": "Error if compression fails, invalid parameters, or unsupported format"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "since",
|
|
39
|
+
"text": "7.0.0"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "example",
|
|
43
|
+
"text": "```typescript\n// Web - Compress from file input\nconst fileInput = document.getElementById('file') as HTMLInputElement;\nconst file = fileInput.files[0];\nconst result = await FileCompressor.compressImage({\n blob: file,\n quality: 0.8,\n width: 1200,\n mimeType: 'image/jpeg'\n});\nconst url = URL.createObjectURL(result.blob);\n```"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "example",
|
|
47
|
+
"text": "```typescript\n// iOS - Compress image from file path\nconst result = await FileCompressor.compressImage({\n path: 'file:///var/mobile/Containers/Data/image.jpg',\n quality: 0.7,\n width: 1000,\n mimeType: 'image/jpeg' // Only JPEG supported on iOS\n});\nconsole.log('Compressed to:', result.path);\n```"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "example",
|
|
51
|
+
"text": "```typescript\n// Android - Compress with WebP format\nconst result = await FileCompressor.compressImage({\n path: 'content://downloads/document/123',\n quality: 0.6,\n width: 800,\n height: 600,\n mimeType: 'image/webp'\n});\nconsole.log('Compressed to:', result.path);\n```"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "example",
|
|
55
|
+
"text": "```typescript\n// Maintain aspect ratio - only specify width\nconst result = await FileCompressor.compressImage({\n path: imagePath,\n quality: 0.75,\n width: 1920, // Height calculated automatically\n mimeType: 'image/jpeg'\n});\n```"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"docs": "Compresses an image file with specified dimensions and quality settings.\n\nThis method compresses images to reduce file size while maintaining acceptable quality.\nIt supports resizing and format conversion (JPEG/WebP depending on platform).\n\n**Important Notes:**\n- EXIF metadata is removed during compression on all platforms\n- Aspect ratio is automatically maintained if only one dimension is provided\n- Compressed files are saved to temporary directories on native platforms",
|
|
59
|
+
"complexTypes": [
|
|
60
|
+
"CompressImageResult",
|
|
61
|
+
"CompressImageOptions"
|
|
62
|
+
],
|
|
63
|
+
"slug": "compressimage"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"name": "getPluginVersion",
|
|
67
|
+
"signature": "() => Promise<{ version: string; }>",
|
|
68
|
+
"parameters": [],
|
|
69
|
+
"returns": "Promise<{ version: string; }>",
|
|
70
|
+
"tags": [
|
|
71
|
+
{
|
|
72
|
+
"name": "returns",
|
|
73
|
+
"text": "Promise that resolves with the plugin version string"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"name": "throws",
|
|
77
|
+
"text": "Error if getting the version fails"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"name": "since",
|
|
81
|
+
"text": "7.0.0"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name": "example",
|
|
85
|
+
"text": "```typescript\nconst { version } = await FileCompressor.getPluginVersion();\nconsole.log('Plugin version:', version); // \"7.0.0\"\n```"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"docs": "Get the native Capacitor plugin version.\n\nReturns the version of the native plugin implementation.\nUseful for debugging and ensuring compatibility.",
|
|
89
|
+
"complexTypes": [],
|
|
90
|
+
"slug": "getpluginversion"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"properties": []
|
|
94
|
+
},
|
|
95
|
+
"interfaces": [
|
|
96
|
+
{
|
|
97
|
+
"name": "CompressImageResult",
|
|
98
|
+
"slug": "compressimageresult",
|
|
99
|
+
"docs": "The result of compressing an image.\n\nContains either a file path (native platforms) or a Blob (web platform)\ndepending on where the compression was performed.",
|
|
100
|
+
"tags": [
|
|
101
|
+
{
|
|
102
|
+
"text": "7.0.0",
|
|
103
|
+
"name": "since"
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
"methods": [],
|
|
107
|
+
"properties": [
|
|
108
|
+
{
|
|
109
|
+
"name": "path",
|
|
110
|
+
"tags": [
|
|
111
|
+
{
|
|
112
|
+
"text": "7.0.0",
|
|
113
|
+
"name": "since"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"text": "\"/var/mobile/Containers/Data/tmp/compressed_abc123.jpg\" // iOS",
|
|
117
|
+
"name": "example"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"text": "\"/data/user/0/com.app/cache/compressed_xyz789.jpg\" // Android",
|
|
121
|
+
"name": "example"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"docs": "The file path of the compressed image.\n\n**Platform:** Android, iOS only (undefined on Web)\n\nPoints to a temporary file containing the compressed image.\nOn iOS, typically in `NSTemporaryDirectory()`.\nOn Android, typically in app cache directory.\n\n**Important:** These files may be cleaned up by the OS.\nCopy to permanent storage if needed for long-term use.",
|
|
125
|
+
"complexTypes": [],
|
|
126
|
+
"type": "string | undefined"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "blob",
|
|
130
|
+
"tags": [
|
|
131
|
+
{
|
|
132
|
+
"text": "7.0.0",
|
|
133
|
+
"name": "since"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"text": "```typescript\n// Create preview URL\nconst url = URL.createObjectURL(result.blob);\nimageElement.src = url;\n```",
|
|
137
|
+
"name": "example"
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"text": "```typescript\n// Upload to server\nconst formData = new FormData();\nformData.append('image', result.blob, 'compressed.jpg');\nawait fetch('/upload', { method: 'POST', body: formData });\n```",
|
|
141
|
+
"name": "example"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"docs": "The blob of the compressed image.\n\n**Platform:** Web only (undefined on iOS/Android)\n\nA Blob object containing the compressed image data.\nCan be used to:\n- Create object URLs for preview: `URL.createObjectURL(blob)`\n- Upload to server via FormData\n- Save to IndexedDB or other storage\n- Convert to base64 with FileReader",
|
|
145
|
+
"complexTypes": [
|
|
146
|
+
"Blob"
|
|
147
|
+
],
|
|
148
|
+
"type": "Blob"
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "CompressImageOptions",
|
|
154
|
+
"slug": "compressimageoptions",
|
|
155
|
+
"docs": "Options for compressing an image.\n\nConfigure the compression behavior including quality, dimensions, and output format.\nPlatform-specific options are available for path (native) and blob (web).",
|
|
156
|
+
"tags": [
|
|
157
|
+
{
|
|
158
|
+
"text": "7.0.0",
|
|
159
|
+
"name": "since"
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"methods": [],
|
|
163
|
+
"properties": [
|
|
164
|
+
{
|
|
165
|
+
"name": "path",
|
|
166
|
+
"tags": [
|
|
167
|
+
{
|
|
168
|
+
"text": "7.0.0",
|
|
169
|
+
"name": "since"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"text": "\"file:///var/mobile/Containers/Data/Application/image.jpg\" // iOS",
|
|
173
|
+
"name": "example"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
"text": "\"content://com.android.providers.downloads.documents/document/msf%3A1000000485\" // Android",
|
|
177
|
+
"name": "example"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"text": "\"/storage/emulated/0/Download/photo.png\" // Android absolute path",
|
|
181
|
+
"name": "example"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"docs": "The file path of the image to compress.\n\n**Platform:** Android, iOS only (not supported on Web)\n\nAccepts various path formats:\n- iOS: `file://` URLs or absolute paths\n- Android: `content://` URIs, `file://` URLs, or absolute paths",
|
|
185
|
+
"complexTypes": [],
|
|
186
|
+
"type": "string | undefined"
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"name": "blob",
|
|
190
|
+
"tags": [
|
|
191
|
+
{
|
|
192
|
+
"text": "7.0.0",
|
|
193
|
+
"name": "since"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"text": "```typescript\n// From file input\nconst fileInput = document.getElementById('file') as HTMLInputElement;\nconst blob = fileInput.files[0];\n```",
|
|
197
|
+
"name": "example"
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"text": "```typescript\n// From fetch\nconst response = await fetch('https://example.com/image.jpg');\nconst blob = await response.blob();\n```",
|
|
201
|
+
"name": "example"
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
"docs": "The file blob of the image to compress.\n\n**Platform:** Web only (not supported on iOS/Android)\n\nUse this when compressing images from file inputs, fetch responses,\nor any other Blob source in web applications.",
|
|
205
|
+
"complexTypes": [
|
|
206
|
+
"Blob"
|
|
207
|
+
],
|
|
208
|
+
"type": "Blob"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"name": "quality",
|
|
212
|
+
"tags": [
|
|
213
|
+
{
|
|
214
|
+
"text": "7.0.0",
|
|
215
|
+
"name": "since"
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
"text": "0.6",
|
|
219
|
+
"name": "default"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"text": "0.8 // High quality",
|
|
223
|
+
"name": "example"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"text": "0.5 // Medium quality, smaller file",
|
|
227
|
+
"name": "example"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"text": "0.3 // Low quality, very small file",
|
|
231
|
+
"name": "example"
|
|
232
|
+
}
|
|
233
|
+
],
|
|
234
|
+
"docs": "The quality of the compressed image.\n\n**Range:** 0.0 to 1.0\n- `0.0` = Maximum compression (lowest quality, smallest file)\n- `1.0` = Minimum compression (highest quality, largest file)\n- `0.6` = Default balanced compression\n\n**Platform:** All platforms\n\nHigher quality values result in larger files but better visual quality.\nThe actual compression ratio depends on the image content and format.",
|
|
235
|
+
"complexTypes": [],
|
|
236
|
+
"type": "number | undefined"
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
"name": "width",
|
|
240
|
+
"tags": [
|
|
241
|
+
{
|
|
242
|
+
"text": "7.0.0",
|
|
243
|
+
"name": "since"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"text": "1920 // Full HD width",
|
|
247
|
+
"name": "example"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"text": "1200 // Common web image width",
|
|
251
|
+
"name": "example"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"text": "800 // Mobile-optimized width",
|
|
255
|
+
"name": "example"
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
"docs": "The width of the compressed image in pixels.\n\n**Platform:** All platforms\n\nIf only width is specified, height is calculated automatically\nto maintain the original aspect ratio.\n\nIf both width and height are specified, the image is resized\nto exact dimensions (may distort if ratio differs).",
|
|
259
|
+
"complexTypes": [],
|
|
260
|
+
"type": "number | undefined"
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"name": "height",
|
|
264
|
+
"tags": [
|
|
265
|
+
{
|
|
266
|
+
"text": "7.0.0",
|
|
267
|
+
"name": "since"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"text": "1080 // Full HD height",
|
|
271
|
+
"name": "example"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"text": "800 // Common web image height",
|
|
275
|
+
"name": "example"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"text": "600 // Mobile-optimized height",
|
|
279
|
+
"name": "example"
|
|
280
|
+
}
|
|
281
|
+
],
|
|
282
|
+
"docs": "The height of the compressed image in pixels.\n\n**Platform:** All platforms\n\nIf only height is specified, width is calculated automatically\nto maintain the original aspect ratio.\n\nIf both width and height are specified, the image is resized\nto exact dimensions (may distort if ratio differs).",
|
|
283
|
+
"complexTypes": [],
|
|
284
|
+
"type": "number | undefined"
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"name": "mimeType",
|
|
288
|
+
"tags": [
|
|
289
|
+
{
|
|
290
|
+
"text": "7.0.0",
|
|
291
|
+
"name": "since"
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
"text": "\"image/jpeg\"",
|
|
295
|
+
"name": "default"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"text": "\"image/jpeg\" // JPEG format (all platforms)",
|
|
299
|
+
"name": "example"
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"text": "\"image/webp\" // WebP format (Android/Web only)",
|
|
303
|
+
"name": "example"
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
"docs": "The MIME type of the compressed output image.\n\n**Platform Support:**\n- **iOS:** `image/jpeg` only\n- **Android:** `image/jpeg`, `image/webp`\n- **Web:** `image/jpeg`, `image/webp`\n\n**Format Characteristics:**\n- **JPEG:** Universal support, good for photos, no transparency\n- **WebP:** Better compression, supports transparency, not on iOS",
|
|
307
|
+
"complexTypes": [],
|
|
308
|
+
"type": "string | undefined"
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
],
|
|
313
|
+
"enums": [],
|
|
314
|
+
"typeAliases": [],
|
|
315
|
+
"pluginConfigs": []
|
|
316
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capacitor File Compressor Plugin interface for image compression.
|
|
3
|
+
*
|
|
4
|
+
* @since 7.0.0
|
|
5
|
+
*/
|
|
6
|
+
export interface FileCompressorPlugin {
|
|
7
|
+
/**
|
|
8
|
+
* Compresses an image file with specified dimensions and quality settings.
|
|
9
|
+
*
|
|
10
|
+
* This method compresses images to reduce file size while maintaining acceptable quality.
|
|
11
|
+
* It supports resizing and format conversion (JPEG/WebP depending on platform).
|
|
12
|
+
*
|
|
13
|
+
* **Important Notes:**
|
|
14
|
+
* - EXIF metadata is removed during compression on all platforms
|
|
15
|
+
* - Aspect ratio is automatically maintained if only one dimension is provided
|
|
16
|
+
* - Compressed files are saved to temporary directories on native platforms
|
|
17
|
+
*
|
|
18
|
+
* @param options - Configuration options for image compression
|
|
19
|
+
* @returns Promise that resolves with the compressed image path or blob
|
|
20
|
+
* @throws Error if compression fails, invalid parameters, or unsupported format
|
|
21
|
+
* @since 7.0.0
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // Web - Compress from file input
|
|
25
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
26
|
+
* const file = fileInput.files[0];
|
|
27
|
+
* const result = await FileCompressor.compressImage({
|
|
28
|
+
* blob: file,
|
|
29
|
+
* quality: 0.8,
|
|
30
|
+
* width: 1200,
|
|
31
|
+
* mimeType: 'image/jpeg'
|
|
32
|
+
* });
|
|
33
|
+
* const url = URL.createObjectURL(result.blob);
|
|
34
|
+
* ```
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* // iOS - Compress image from file path
|
|
38
|
+
* const result = await FileCompressor.compressImage({
|
|
39
|
+
* path: 'file:///var/mobile/Containers/Data/image.jpg',
|
|
40
|
+
* quality: 0.7,
|
|
41
|
+
* width: 1000,
|
|
42
|
+
* mimeType: 'image/jpeg' // Only JPEG supported on iOS
|
|
43
|
+
* });
|
|
44
|
+
* console.log('Compressed to:', result.path);
|
|
45
|
+
* ```
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Android - Compress with WebP format
|
|
49
|
+
* const result = await FileCompressor.compressImage({
|
|
50
|
+
* path: 'content://downloads/document/123',
|
|
51
|
+
* quality: 0.6,
|
|
52
|
+
* width: 800,
|
|
53
|
+
* height: 600,
|
|
54
|
+
* mimeType: 'image/webp'
|
|
55
|
+
* });
|
|
56
|
+
* console.log('Compressed to:', result.path);
|
|
57
|
+
* ```
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Maintain aspect ratio - only specify width
|
|
61
|
+
* const result = await FileCompressor.compressImage({
|
|
62
|
+
* path: imagePath,
|
|
63
|
+
* quality: 0.75,
|
|
64
|
+
* width: 1920, // Height calculated automatically
|
|
65
|
+
* mimeType: 'image/jpeg'
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
compressImage(options: CompressImageOptions): Promise<CompressImageResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Get the native Capacitor plugin version.
|
|
72
|
+
*
|
|
73
|
+
* Returns the version of the native plugin implementation.
|
|
74
|
+
* Useful for debugging and ensuring compatibility.
|
|
75
|
+
*
|
|
76
|
+
* @returns Promise that resolves with the plugin version string
|
|
77
|
+
* @throws Error if getting the version fails
|
|
78
|
+
* @since 7.0.0
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const { version } = await FileCompressor.getPluginVersion();
|
|
82
|
+
* console.log('Plugin version:', version); // "7.0.0"
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
getPluginVersion(): Promise<{
|
|
86
|
+
version: string;
|
|
87
|
+
}>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Options for compressing an image.
|
|
91
|
+
*
|
|
92
|
+
* Configure the compression behavior including quality, dimensions, and output format.
|
|
93
|
+
* Platform-specific options are available for path (native) and blob (web).
|
|
94
|
+
*
|
|
95
|
+
* @since 7.0.0
|
|
96
|
+
*/
|
|
97
|
+
export interface CompressImageOptions {
|
|
98
|
+
/**
|
|
99
|
+
* The file path of the image to compress.
|
|
100
|
+
*
|
|
101
|
+
* **Platform:** Android, iOS only (not supported on Web)
|
|
102
|
+
*
|
|
103
|
+
* Accepts various path formats:
|
|
104
|
+
* - iOS: `file://` URLs or absolute paths
|
|
105
|
+
* - Android: `content://` URIs, `file://` URLs, or absolute paths
|
|
106
|
+
*
|
|
107
|
+
* @since 7.0.0
|
|
108
|
+
* @example "file:///var/mobile/Containers/Data/Application/image.jpg" // iOS
|
|
109
|
+
* @example "content://com.android.providers.downloads.documents/document/msf%3A1000000485" // Android
|
|
110
|
+
* @example "/storage/emulated/0/Download/photo.png" // Android absolute path
|
|
111
|
+
*/
|
|
112
|
+
path?: string;
|
|
113
|
+
/**
|
|
114
|
+
* The file blob of the image to compress.
|
|
115
|
+
*
|
|
116
|
+
* **Platform:** Web only (not supported on iOS/Android)
|
|
117
|
+
*
|
|
118
|
+
* Use this when compressing images from file inputs, fetch responses,
|
|
119
|
+
* or any other Blob source in web applications.
|
|
120
|
+
*
|
|
121
|
+
* @since 7.0.0
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* // From file input
|
|
125
|
+
* const fileInput = document.getElementById('file') as HTMLInputElement;
|
|
126
|
+
* const blob = fileInput.files[0];
|
|
127
|
+
* ```
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // From fetch
|
|
131
|
+
* const response = await fetch('https://example.com/image.jpg');
|
|
132
|
+
* const blob = await response.blob();
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
blob?: Blob;
|
|
136
|
+
/**
|
|
137
|
+
* The quality of the compressed image.
|
|
138
|
+
*
|
|
139
|
+
* **Range:** 0.0 to 1.0
|
|
140
|
+
* - `0.0` = Maximum compression (lowest quality, smallest file)
|
|
141
|
+
* - `1.0` = Minimum compression (highest quality, largest file)
|
|
142
|
+
* - `0.6` = Default balanced compression
|
|
143
|
+
*
|
|
144
|
+
* **Platform:** All platforms
|
|
145
|
+
*
|
|
146
|
+
* Higher quality values result in larger files but better visual quality.
|
|
147
|
+
* The actual compression ratio depends on the image content and format.
|
|
148
|
+
*
|
|
149
|
+
* @since 7.0.0
|
|
150
|
+
* @default 0.6
|
|
151
|
+
* @example 0.8 // High quality
|
|
152
|
+
* @example 0.5 // Medium quality, smaller file
|
|
153
|
+
* @example 0.3 // Low quality, very small file
|
|
154
|
+
*/
|
|
155
|
+
quality?: number;
|
|
156
|
+
/**
|
|
157
|
+
* The width of the compressed image in pixels.
|
|
158
|
+
*
|
|
159
|
+
* **Platform:** All platforms
|
|
160
|
+
*
|
|
161
|
+
* If only width is specified, height is calculated automatically
|
|
162
|
+
* to maintain the original aspect ratio.
|
|
163
|
+
*
|
|
164
|
+
* If both width and height are specified, the image is resized
|
|
165
|
+
* to exact dimensions (may distort if ratio differs).
|
|
166
|
+
*
|
|
167
|
+
* @since 7.0.0
|
|
168
|
+
* @example 1920 // Full HD width
|
|
169
|
+
* @example 1200 // Common web image width
|
|
170
|
+
* @example 800 // Mobile-optimized width
|
|
171
|
+
*/
|
|
172
|
+
width?: number;
|
|
173
|
+
/**
|
|
174
|
+
* The height of the compressed image in pixels.
|
|
175
|
+
*
|
|
176
|
+
* **Platform:** All platforms
|
|
177
|
+
*
|
|
178
|
+
* If only height is specified, width is calculated automatically
|
|
179
|
+
* to maintain the original aspect ratio.
|
|
180
|
+
*
|
|
181
|
+
* If both width and height are specified, the image is resized
|
|
182
|
+
* to exact dimensions (may distort if ratio differs).
|
|
183
|
+
*
|
|
184
|
+
* @since 7.0.0
|
|
185
|
+
* @example 1080 // Full HD height
|
|
186
|
+
* @example 800 // Common web image height
|
|
187
|
+
* @example 600 // Mobile-optimized height
|
|
188
|
+
*/
|
|
189
|
+
height?: number;
|
|
190
|
+
/**
|
|
191
|
+
* The MIME type of the compressed output image.
|
|
192
|
+
*
|
|
193
|
+
* **Platform Support:**
|
|
194
|
+
* - **iOS:** `image/jpeg` only
|
|
195
|
+
* - **Android:** `image/jpeg`, `image/webp`
|
|
196
|
+
* - **Web:** `image/jpeg`, `image/webp`
|
|
197
|
+
*
|
|
198
|
+
* **Format Characteristics:**
|
|
199
|
+
* - **JPEG:** Universal support, good for photos, no transparency
|
|
200
|
+
* - **WebP:** Better compression, supports transparency, not on iOS
|
|
201
|
+
*
|
|
202
|
+
* @since 7.0.0
|
|
203
|
+
* @default "image/jpeg"
|
|
204
|
+
* @example "image/jpeg" // JPEG format (all platforms)
|
|
205
|
+
* @example "image/webp" // WebP format (Android/Web only)
|
|
206
|
+
*/
|
|
207
|
+
mimeType?: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* The result of compressing an image.
|
|
211
|
+
*
|
|
212
|
+
* Contains either a file path (native platforms) or a Blob (web platform)
|
|
213
|
+
* depending on where the compression was performed.
|
|
214
|
+
*
|
|
215
|
+
* @since 7.0.0
|
|
216
|
+
*/
|
|
217
|
+
export interface CompressImageResult {
|
|
218
|
+
/**
|
|
219
|
+
* The file path of the compressed image.
|
|
220
|
+
*
|
|
221
|
+
* **Platform:** Android, iOS only (undefined on Web)
|
|
222
|
+
*
|
|
223
|
+
* Points to a temporary file containing the compressed image.
|
|
224
|
+
* On iOS, typically in `NSTemporaryDirectory()`.
|
|
225
|
+
* On Android, typically in app cache directory.
|
|
226
|
+
*
|
|
227
|
+
* **Important:** These files may be cleaned up by the OS.
|
|
228
|
+
* Copy to permanent storage if needed for long-term use.
|
|
229
|
+
*
|
|
230
|
+
* @since 7.0.0
|
|
231
|
+
* @example "/var/mobile/Containers/Data/tmp/compressed_abc123.jpg" // iOS
|
|
232
|
+
* @example "/data/user/0/com.app/cache/compressed_xyz789.jpg" // Android
|
|
233
|
+
*/
|
|
234
|
+
path?: string;
|
|
235
|
+
/**
|
|
236
|
+
* The blob of the compressed image.
|
|
237
|
+
*
|
|
238
|
+
* **Platform:** Web only (undefined on iOS/Android)
|
|
239
|
+
*
|
|
240
|
+
* A Blob object containing the compressed image data.
|
|
241
|
+
* Can be used to:
|
|
242
|
+
* - Create object URLs for preview: `URL.createObjectURL(blob)`
|
|
243
|
+
* - Upload to server via FormData
|
|
244
|
+
* - Save to IndexedDB or other storage
|
|
245
|
+
* - Convert to base64 with FileReader
|
|
246
|
+
*
|
|
247
|
+
* @since 7.0.0
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* // Create preview URL
|
|
251
|
+
* const url = URL.createObjectURL(result.blob);
|
|
252
|
+
* imageElement.src = url;
|
|
253
|
+
* ```
|
|
254
|
+
* @example
|
|
255
|
+
* ```typescript
|
|
256
|
+
* // Upload to server
|
|
257
|
+
* const formData = new FormData();
|
|
258
|
+
* formData.append('image', result.blob, 'compressed.jpg');
|
|
259
|
+
* await fetch('/upload', { method: 'POST', body: formData });
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
blob?: Blob;
|
|
263
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Capacitor File Compressor Plugin interface for image compression.\n *\n * @since 7.0.0\n */\nexport interface FileCompressorPlugin {\n /**\n * Compresses an image file with specified dimensions and quality settings.\n *\n * This method compresses images to reduce file size while maintaining acceptable quality.\n * It supports resizing and format conversion (JPEG/WebP depending on platform).\n *\n * **Important Notes:**\n * - EXIF metadata is removed during compression on all platforms\n * - Aspect ratio is automatically maintained if only one dimension is provided\n * - Compressed files are saved to temporary directories on native platforms\n *\n * @param options - Configuration options for image compression\n * @returns Promise that resolves with the compressed image path or blob\n * @throws Error if compression fails, invalid parameters, or unsupported format\n * @since 7.0.0\n * @example\n * ```typescript\n * // Web - Compress from file input\n * const fileInput = document.getElementById('file') as HTMLInputElement;\n * const file = fileInput.files[0];\n * const result = await FileCompressor.compressImage({\n * blob: file,\n * quality: 0.8,\n * width: 1200,\n * mimeType: 'image/jpeg'\n * });\n * const url = URL.createObjectURL(result.blob);\n * ```\n * @example\n * ```typescript\n * // iOS - Compress image from file path\n * const result = await FileCompressor.compressImage({\n * path: 'file:///var/mobile/Containers/Data/image.jpg',\n * quality: 0.7,\n * width: 1000,\n * mimeType: 'image/jpeg' // Only JPEG supported on iOS\n * });\n * console.log('Compressed to:', result.path);\n * ```\n * @example\n * ```typescript\n * // Android - Compress with WebP format\n * const result = await FileCompressor.compressImage({\n * path: 'content://downloads/document/123',\n * quality: 0.6,\n * width: 800,\n * height: 600,\n * mimeType: 'image/webp'\n * });\n * console.log('Compressed to:', result.path);\n * ```\n * @example\n * ```typescript\n * // Maintain aspect ratio - only specify width\n * const result = await FileCompressor.compressImage({\n * path: imagePath,\n * quality: 0.75,\n * width: 1920, // Height calculated automatically\n * mimeType: 'image/jpeg'\n * });\n * ```\n */\n compressImage(options: CompressImageOptions): Promise<CompressImageResult>;\n\n /**\n * Get the native Capacitor plugin version.\n *\n * Returns the version of the native plugin implementation.\n * Useful for debugging and ensuring compatibility.\n *\n * @returns Promise that resolves with the plugin version string\n * @throws Error if getting the version fails\n * @since 7.0.0\n * @example\n * ```typescript\n * const { version } = await FileCompressor.getPluginVersion();\n * console.log('Plugin version:', version); // \"7.0.0\"\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n\n/**\n * Options for compressing an image.\n *\n * Configure the compression behavior including quality, dimensions, and output format.\n * Platform-specific options are available for path (native) and blob (web).\n *\n * @since 7.0.0\n */\nexport interface CompressImageOptions {\n /**\n * The file path of the image to compress.\n *\n * **Platform:** Android, iOS only (not supported on Web)\n *\n * Accepts various path formats:\n * - iOS: `file://` URLs or absolute paths\n * - Android: `content://` URIs, `file://` URLs, or absolute paths\n *\n * @since 7.0.0\n * @example \"file:///var/mobile/Containers/Data/Application/image.jpg\" // iOS\n * @example \"content://com.android.providers.downloads.documents/document/msf%3A1000000485\" // Android\n * @example \"/storage/emulated/0/Download/photo.png\" // Android absolute path\n */\n path?: string;\n\n /**\n * The file blob of the image to compress.\n *\n * **Platform:** Web only (not supported on iOS/Android)\n *\n * Use this when compressing images from file inputs, fetch responses,\n * or any other Blob source in web applications.\n *\n * @since 7.0.0\n * @example\n * ```typescript\n * // From file input\n * const fileInput = document.getElementById('file') as HTMLInputElement;\n * const blob = fileInput.files[0];\n * ```\n * @example\n * ```typescript\n * // From fetch\n * const response = await fetch('https://example.com/image.jpg');\n * const blob = await response.blob();\n * ```\n */\n blob?: Blob;\n\n /**\n * The quality of the compressed image.\n *\n * **Range:** 0.0 to 1.0\n * - `0.0` = Maximum compression (lowest quality, smallest file)\n * - `1.0` = Minimum compression (highest quality, largest file)\n * - `0.6` = Default balanced compression\n *\n * **Platform:** All platforms\n *\n * Higher quality values result in larger files but better visual quality.\n * The actual compression ratio depends on the image content and format.\n *\n * @since 7.0.0\n * @default 0.6\n * @example 0.8 // High quality\n * @example 0.5 // Medium quality, smaller file\n * @example 0.3 // Low quality, very small file\n */\n quality?: number;\n\n /**\n * The width of the compressed image in pixels.\n *\n * **Platform:** All platforms\n *\n * If only width is specified, height is calculated automatically\n * to maintain the original aspect ratio.\n *\n * If both width and height are specified, the image is resized\n * to exact dimensions (may distort if ratio differs).\n *\n * @since 7.0.0\n * @example 1920 // Full HD width\n * @example 1200 // Common web image width\n * @example 800 // Mobile-optimized width\n */\n width?: number;\n\n /**\n * The height of the compressed image in pixels.\n *\n * **Platform:** All platforms\n *\n * If only height is specified, width is calculated automatically\n * to maintain the original aspect ratio.\n *\n * If both width and height are specified, the image is resized\n * to exact dimensions (may distort if ratio differs).\n *\n * @since 7.0.0\n * @example 1080 // Full HD height\n * @example 800 // Common web image height\n * @example 600 // Mobile-optimized height\n */\n height?: number;\n\n /**\n * The MIME type of the compressed output image.\n *\n * **Platform Support:**\n * - **iOS:** `image/jpeg` only\n * - **Android:** `image/jpeg`, `image/webp`\n * - **Web:** `image/jpeg`, `image/webp`\n *\n * **Format Characteristics:**\n * - **JPEG:** Universal support, good for photos, no transparency\n * - **WebP:** Better compression, supports transparency, not on iOS\n *\n * @since 7.0.0\n * @default \"image/jpeg\"\n * @example \"image/jpeg\" // JPEG format (all platforms)\n * @example \"image/webp\" // WebP format (Android/Web only)\n */\n mimeType?: string;\n}\n\n/**\n * The result of compressing an image.\n *\n * Contains either a file path (native platforms) or a Blob (web platform)\n * depending on where the compression was performed.\n *\n * @since 7.0.0\n */\nexport interface CompressImageResult {\n /**\n * The file path of the compressed image.\n *\n * **Platform:** Android, iOS only (undefined on Web)\n *\n * Points to a temporary file containing the compressed image.\n * On iOS, typically in `NSTemporaryDirectory()`.\n * On Android, typically in app cache directory.\n *\n * **Important:** These files may be cleaned up by the OS.\n * Copy to permanent storage if needed for long-term use.\n *\n * @since 7.0.0\n * @example \"/var/mobile/Containers/Data/tmp/compressed_abc123.jpg\" // iOS\n * @example \"/data/user/0/com.app/cache/compressed_xyz789.jpg\" // Android\n */\n path?: string;\n\n /**\n * The blob of the compressed image.\n *\n * **Platform:** Web only (undefined on iOS/Android)\n *\n * A Blob object containing the compressed image data.\n * Can be used to:\n * - Create object URLs for preview: `URL.createObjectURL(blob)`\n * - Upload to server via FormData\n * - Save to IndexedDB or other storage\n * - Convert to base64 with FileReader\n *\n * @since 7.0.0\n * @example\n * ```typescript\n * // Create preview URL\n * const url = URL.createObjectURL(result.blob);\n * imageElement.src = url;\n * ```\n * @example\n * ```typescript\n * // Upload to server\n * const formData = new FormData();\n * formData.append('image', result.blob, 'compressed.jpg');\n * await fetch('/upload', { method: 'POST', body: formData });\n * ```\n */\n blob?: Blob;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const FileCompressor = registerPlugin('FileCompressor', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.FileCompressorWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { FileCompressor };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,cAAc,GAAG,cAAc,CAAuB,gBAAgB,EAAE;IAC5E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,iBAAiB,EAAE,CAAC;CAClE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { FileCompressorPlugin } from './definitions';\n\nconst FileCompressor = registerPlugin<FileCompressorPlugin>('FileCompressor', {\n web: () => import('./web').then((m) => new m.FileCompressorWeb()),\n});\n\nexport * from './definitions';\nexport { FileCompressor };\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CompressImageOptions, CompressImageResult, FileCompressorPlugin } from './definitions';
|
|
3
|
+
export declare class FileCompressorWeb extends WebPlugin implements FileCompressorPlugin {
|
|
4
|
+
compressImage(options: CompressImageOptions): Promise<CompressImageResult>;
|
|
5
|
+
getPluginVersion(): Promise<{
|
|
6
|
+
version: string;
|
|
7
|
+
}>;
|
|
8
|
+
private createImageFromBlob;
|
|
9
|
+
}
|