@openfn/language-image-utils 1.0.0 → 1.0.2
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/ast.json +506 -1
- package/dist/index.cjs +2 -4
- package/dist/index.js +2 -3
- package/package.json +3 -5
- package/types/Adaptor.d.ts +10 -7
package/ast.json
CHANGED
|
@@ -1,5 +1,510 @@
|
|
|
1
1
|
{
|
|
2
|
-
"operations": [
|
|
2
|
+
"operations": [
|
|
3
|
+
{
|
|
4
|
+
"name": "resize",
|
|
5
|
+
"params": [
|
|
6
|
+
"base64ImgOrBuffer",
|
|
7
|
+
"options"
|
|
8
|
+
],
|
|
9
|
+
"docs": {
|
|
10
|
+
"description": "Resize an image to the given dimensions.\nWrites `{ buffer, width, height }` to `state.data`.",
|
|
11
|
+
"tags": [
|
|
12
|
+
{
|
|
13
|
+
"title": "public",
|
|
14
|
+
"description": null,
|
|
15
|
+
"type": null
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"title": "example",
|
|
19
|
+
"description": "resize($.data.photoBase64, { width: 1200, height: 1600 })"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"title": "function",
|
|
23
|
+
"description": null,
|
|
24
|
+
"name": null
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"title": "param",
|
|
28
|
+
"description": "Base64 string, data URL, Buffer, or resolver fn",
|
|
29
|
+
"type": {
|
|
30
|
+
"type": "UnionType",
|
|
31
|
+
"elements": [
|
|
32
|
+
{
|
|
33
|
+
"type": "NameExpression",
|
|
34
|
+
"name": "string"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"type": "NameExpression",
|
|
38
|
+
"name": "Buffer"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"type": "NameExpression",
|
|
42
|
+
"name": "Function"
|
|
43
|
+
}
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
"name": "base64ImgOrBuffer"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"title": "param",
|
|
50
|
+
"description": null,
|
|
51
|
+
"type": {
|
|
52
|
+
"type": "OptionalType",
|
|
53
|
+
"expression": {
|
|
54
|
+
"type": "NameExpression",
|
|
55
|
+
"name": "object"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"name": "options",
|
|
59
|
+
"default": "{}"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"title": "param",
|
|
63
|
+
"description": "Output width in pixels",
|
|
64
|
+
"type": {
|
|
65
|
+
"type": "OptionalType",
|
|
66
|
+
"expression": {
|
|
67
|
+
"type": "NameExpression",
|
|
68
|
+
"name": "number"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"name": "options.width"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"title": "param",
|
|
75
|
+
"description": "Output height in pixels",
|
|
76
|
+
"type": {
|
|
77
|
+
"type": "OptionalType",
|
|
78
|
+
"expression": {
|
|
79
|
+
"type": "NameExpression",
|
|
80
|
+
"name": "number"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"name": "options.height"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"title": "param",
|
|
87
|
+
"description": "Return format: `'buffer'` (default) or `'base64'`",
|
|
88
|
+
"type": {
|
|
89
|
+
"type": "OptionalType",
|
|
90
|
+
"expression": {
|
|
91
|
+
"type": "UnionType",
|
|
92
|
+
"elements": [
|
|
93
|
+
{
|
|
94
|
+
"type": "StringLiteralType",
|
|
95
|
+
"value": "buffer"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "StringLiteralType",
|
|
99
|
+
"value": "base64"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"name": "options.parseAs",
|
|
105
|
+
"default": "'buffer'"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"title": "state",
|
|
109
|
+
"description": "{ImageState}"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"title": "returns",
|
|
113
|
+
"description": null,
|
|
114
|
+
"type": {
|
|
115
|
+
"type": "NameExpression",
|
|
116
|
+
"name": "Operation"
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"valid": false
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"name": "compress",
|
|
125
|
+
"params": [
|
|
126
|
+
"base64ImgOrBuffer",
|
|
127
|
+
"options"
|
|
128
|
+
],
|
|
129
|
+
"docs": {
|
|
130
|
+
"description": "Compress an image by reducing image quality until it reaches the criteria.\nWrites `{ buffer, size, quality }` to `state.data`.",
|
|
131
|
+
"tags": [
|
|
132
|
+
{
|
|
133
|
+
"title": "public",
|
|
134
|
+
"description": null,
|
|
135
|
+
"type": null
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"title": "example",
|
|
139
|
+
"description": "compress(state.data.buffer, { maxBytes: 700 * 1024, minQuality: 20 })"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"title": "function",
|
|
143
|
+
"description": null,
|
|
144
|
+
"name": null
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"title": "param",
|
|
148
|
+
"description": "Base64 string, data URL, Buffer, or resolver fn",
|
|
149
|
+
"type": {
|
|
150
|
+
"type": "UnionType",
|
|
151
|
+
"elements": [
|
|
152
|
+
{
|
|
153
|
+
"type": "NameExpression",
|
|
154
|
+
"name": "string"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"type": "NameExpression",
|
|
158
|
+
"name": "Buffer"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"type": "NameExpression",
|
|
162
|
+
"name": "Function"
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
"name": "base64ImgOrBuffer"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
"title": "param",
|
|
170
|
+
"description": null,
|
|
171
|
+
"type": {
|
|
172
|
+
"type": "OptionalType",
|
|
173
|
+
"expression": {
|
|
174
|
+
"type": "NameExpression",
|
|
175
|
+
"name": "object"
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
"name": "options",
|
|
179
|
+
"default": "{}"
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"title": "param",
|
|
183
|
+
"description": "Maximum output file size in bytes",
|
|
184
|
+
"type": {
|
|
185
|
+
"type": "OptionalType",
|
|
186
|
+
"expression": {
|
|
187
|
+
"type": "NameExpression",
|
|
188
|
+
"name": "number"
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
"name": "options.maxBytes",
|
|
192
|
+
"default": "716800"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"title": "param",
|
|
196
|
+
"description": "JPEG quality floor (1–100); compression stops here even if maxBytes is not met",
|
|
197
|
+
"type": {
|
|
198
|
+
"type": "OptionalType",
|
|
199
|
+
"expression": {
|
|
200
|
+
"type": "NameExpression",
|
|
201
|
+
"name": "number"
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"name": "options.minQuality",
|
|
205
|
+
"default": "20"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"title": "param",
|
|
209
|
+
"description": "Return format: `'buffer'` (default) or `'base64'`",
|
|
210
|
+
"type": {
|
|
211
|
+
"type": "OptionalType",
|
|
212
|
+
"expression": {
|
|
213
|
+
"type": "UnionType",
|
|
214
|
+
"elements": [
|
|
215
|
+
{
|
|
216
|
+
"type": "StringLiteralType",
|
|
217
|
+
"value": "buffer"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"type": "StringLiteralType",
|
|
221
|
+
"value": "base64"
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
"name": "options.parseAs",
|
|
227
|
+
"default": "'buffer'"
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"title": "state",
|
|
231
|
+
"description": "{ImageState}"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"title": "returns",
|
|
235
|
+
"description": null,
|
|
236
|
+
"type": {
|
|
237
|
+
"type": "NameExpression",
|
|
238
|
+
"name": "Operation"
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
]
|
|
242
|
+
},
|
|
243
|
+
"valid": false
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"name": "stripMetadata",
|
|
247
|
+
"params": [
|
|
248
|
+
"base64ImgOrBuffer",
|
|
249
|
+
"options"
|
|
250
|
+
],
|
|
251
|
+
"docs": {
|
|
252
|
+
"description": "Strip all EXIF metadata from an image. Output is always a JPEG buffer.\nWrites `{ buffer }` to `state.data`.",
|
|
253
|
+
"tags": [
|
|
254
|
+
{
|
|
255
|
+
"title": "public",
|
|
256
|
+
"description": null,
|
|
257
|
+
"type": null
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
"title": "example",
|
|
261
|
+
"description": "stripMetadata($.data.photoBase64)"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"title": "function",
|
|
265
|
+
"description": null,
|
|
266
|
+
"name": null
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
"title": "param",
|
|
270
|
+
"description": "Base64 string, data URL, Buffer, or resolver fn",
|
|
271
|
+
"type": {
|
|
272
|
+
"type": "UnionType",
|
|
273
|
+
"elements": [
|
|
274
|
+
{
|
|
275
|
+
"type": "NameExpression",
|
|
276
|
+
"name": "string"
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"type": "NameExpression",
|
|
280
|
+
"name": "Buffer"
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
"type": "NameExpression",
|
|
284
|
+
"name": "Function"
|
|
285
|
+
}
|
|
286
|
+
]
|
|
287
|
+
},
|
|
288
|
+
"name": "base64ImgOrBuffer"
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
"title": "param",
|
|
292
|
+
"description": null,
|
|
293
|
+
"type": {
|
|
294
|
+
"type": "OptionalType",
|
|
295
|
+
"expression": {
|
|
296
|
+
"type": "NameExpression",
|
|
297
|
+
"name": "object"
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
"name": "options",
|
|
301
|
+
"default": "{}"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"title": "param",
|
|
305
|
+
"description": "Return format: `'buffer'` (default) or `'base64'`",
|
|
306
|
+
"type": {
|
|
307
|
+
"type": "OptionalType",
|
|
308
|
+
"expression": {
|
|
309
|
+
"type": "UnionType",
|
|
310
|
+
"elements": [
|
|
311
|
+
{
|
|
312
|
+
"type": "StringLiteralType",
|
|
313
|
+
"value": "buffer"
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"type": "StringLiteralType",
|
|
317
|
+
"value": "base64"
|
|
318
|
+
}
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
"name": "options.parseAs",
|
|
323
|
+
"default": "'buffer'"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"title": "state",
|
|
327
|
+
"description": "{ImageState}"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"title": "returns",
|
|
331
|
+
"description": null,
|
|
332
|
+
"type": {
|
|
333
|
+
"type": "NameExpression",
|
|
334
|
+
"name": "Operation"
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
]
|
|
338
|
+
},
|
|
339
|
+
"valid": false
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"name": "embedMetadata",
|
|
343
|
+
"params": [
|
|
344
|
+
"base64ImgOrBuffer",
|
|
345
|
+
"exifObj",
|
|
346
|
+
"options"
|
|
347
|
+
],
|
|
348
|
+
"docs": {
|
|
349
|
+
"description": "Embed EXIF metadata into a JPEG image.\nWrites `{ buffer }` to `state.data`.",
|
|
350
|
+
"tags": [
|
|
351
|
+
{
|
|
352
|
+
"title": "public",
|
|
353
|
+
"description": null,
|
|
354
|
+
"type": null
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
"title": "example",
|
|
358
|
+
"description": "embedMetadata($.data.buffer, { UserComment: 'patient-id=42' })\nembedMetadata($.data.buffer, { UserComment: 'patient-id=42', Make: 'OpenFn' }, { parseAs: 'base64' })"
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
"title": "function",
|
|
362
|
+
"description": null,
|
|
363
|
+
"name": null
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"title": "param",
|
|
367
|
+
"description": "Base64 string, data URL, Buffer, or resolver fn",
|
|
368
|
+
"type": {
|
|
369
|
+
"type": "UnionType",
|
|
370
|
+
"elements": [
|
|
371
|
+
{
|
|
372
|
+
"type": "NameExpression",
|
|
373
|
+
"name": "string"
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
"type": "NameExpression",
|
|
377
|
+
"name": "Buffer"
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
"type": "NameExpression",
|
|
381
|
+
"name": "Function"
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
},
|
|
385
|
+
"name": "base64ImgOrBuffer"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"title": "param",
|
|
389
|
+
"description": "EXIF key-value pairs; keys must be valid EXIF tag names (e.g. UserComment, Make, Model)",
|
|
390
|
+
"type": {
|
|
391
|
+
"type": "NameExpression",
|
|
392
|
+
"name": "object"
|
|
393
|
+
},
|
|
394
|
+
"name": "exifObj"
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
"title": "param",
|
|
398
|
+
"description": null,
|
|
399
|
+
"type": {
|
|
400
|
+
"type": "OptionalType",
|
|
401
|
+
"expression": {
|
|
402
|
+
"type": "NameExpression",
|
|
403
|
+
"name": "object"
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
"name": "options",
|
|
407
|
+
"default": "{}"
|
|
408
|
+
},
|
|
409
|
+
{
|
|
410
|
+
"title": "param",
|
|
411
|
+
"description": "Return format: `'buffer'` (default) or `'base64'`",
|
|
412
|
+
"type": {
|
|
413
|
+
"type": "OptionalType",
|
|
414
|
+
"expression": {
|
|
415
|
+
"type": "UnionType",
|
|
416
|
+
"elements": [
|
|
417
|
+
{
|
|
418
|
+
"type": "StringLiteralType",
|
|
419
|
+
"value": "buffer"
|
|
420
|
+
},
|
|
421
|
+
{
|
|
422
|
+
"type": "StringLiteralType",
|
|
423
|
+
"value": "base64"
|
|
424
|
+
}
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
},
|
|
428
|
+
"name": "options.parseAs",
|
|
429
|
+
"default": "'buffer'"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
"title": "state",
|
|
433
|
+
"description": "{ImageState}"
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
"title": "returns",
|
|
437
|
+
"description": null,
|
|
438
|
+
"type": {
|
|
439
|
+
"type": "NameExpression",
|
|
440
|
+
"name": "Operation"
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
]
|
|
444
|
+
},
|
|
445
|
+
"valid": false
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"name": "metadata",
|
|
449
|
+
"params": [
|
|
450
|
+
"base64ImgOrBuffer"
|
|
451
|
+
],
|
|
452
|
+
"docs": {
|
|
453
|
+
"description": "Read image metadata without modifying the image.\nWrites `{ width, height, orientation, size, exif }` to `state.data`.\n`exif` is a flat object of human-readable EXIF tag names (e.g. `{ Make, Model, GPSLatitude, UserComment }`).\n`UserComment` has the `ASCII\\0\\0\\0` encoding prefix stripped. Images with no EXIF return `exif: {}`.",
|
|
454
|
+
"tags": [
|
|
455
|
+
{
|
|
456
|
+
"title": "public",
|
|
457
|
+
"description": null,
|
|
458
|
+
"type": null
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
"title": "example",
|
|
462
|
+
"description": "metadata($.data.photoBase64)\nfn(state => {\n if (state.data.size > 700 * 1024) { ... }\n return state;\n})"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
"title": "function",
|
|
466
|
+
"description": null,
|
|
467
|
+
"name": null
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
"title": "param",
|
|
471
|
+
"description": "Base64 string, data URL, Buffer, or resolver fn",
|
|
472
|
+
"type": {
|
|
473
|
+
"type": "UnionType",
|
|
474
|
+
"elements": [
|
|
475
|
+
{
|
|
476
|
+
"type": "NameExpression",
|
|
477
|
+
"name": "string"
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
"type": "NameExpression",
|
|
481
|
+
"name": "Buffer"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
"type": "NameExpression",
|
|
485
|
+
"name": "Function"
|
|
486
|
+
}
|
|
487
|
+
]
|
|
488
|
+
},
|
|
489
|
+
"name": "base64ImgOrBuffer"
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
"title": "state",
|
|
493
|
+
"description": "{ImageState}"
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
"title": "returns",
|
|
497
|
+
"description": null,
|
|
498
|
+
"type": {
|
|
499
|
+
"type": "NameExpression",
|
|
500
|
+
"name": "Operation"
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
},
|
|
505
|
+
"valid": true
|
|
506
|
+
}
|
|
507
|
+
],
|
|
3
508
|
"exports": [],
|
|
4
509
|
"common": [
|
|
5
510
|
{
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,6 @@ __export(src_exports, {
|
|
|
39
39
|
fields: () => import_language_common2.fields,
|
|
40
40
|
fn: () => import_language_common2.fn,
|
|
41
41
|
fnIf: () => import_language_common2.fnIf,
|
|
42
|
-
getExifData: () => getExifData,
|
|
43
42
|
group: () => import_language_common2.group,
|
|
44
43
|
http: () => import_language_common2.http,
|
|
45
44
|
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
@@ -70,7 +69,6 @@ __export(Adaptor_exports, {
|
|
|
70
69
|
fields: () => import_language_common2.fields,
|
|
71
70
|
fn: () => import_language_common2.fn,
|
|
72
71
|
fnIf: () => import_language_common2.fnIf,
|
|
73
|
-
getExifData: () => getExifData,
|
|
74
72
|
group: () => import_language_common2.group,
|
|
75
73
|
http: () => import_language_common2.http,
|
|
76
74
|
lastReferenceValue: () => import_language_common2.lastReferenceValue,
|
|
@@ -143,7 +141,7 @@ function embedImageMetadata(inputBuffer, kvPairs) {
|
|
|
143
141
|
return { buffer: injectExif(inputBuffer, kvPairs) };
|
|
144
142
|
}
|
|
145
143
|
async function compressImage(inputBuffer, options = {}) {
|
|
146
|
-
const { maxBytes
|
|
144
|
+
const { maxBytes, minQuality } = options;
|
|
147
145
|
const kb = (n) => `${(n / 1024).toFixed(1)}KB`;
|
|
148
146
|
const image = await import_jimp.Jimp.read(inputBuffer);
|
|
149
147
|
let quality = 80;
|
|
@@ -235,6 +233,7 @@ function compress(base64ImgOrBuffer, options = {}) {
|
|
|
235
233
|
base64ImgOrBuffer,
|
|
236
234
|
options
|
|
237
235
|
);
|
|
236
|
+
const { maxBytes = 700 * 1024, minQuality = 20 } = resolvedOptions;
|
|
238
237
|
const result = await compressImage(
|
|
239
238
|
resolveInput(resolvedImg),
|
|
240
239
|
resolvedOptions
|
|
@@ -299,7 +298,6 @@ var src_default = Adaptor_exports;
|
|
|
299
298
|
fields,
|
|
300
299
|
fn,
|
|
301
300
|
fnIf,
|
|
302
|
-
getExifData,
|
|
303
301
|
group,
|
|
304
302
|
http,
|
|
305
303
|
lastReferenceValue,
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,6 @@ __export(Adaptor_exports, {
|
|
|
20
20
|
fields: () => fields,
|
|
21
21
|
fn: () => fn,
|
|
22
22
|
fnIf: () => fnIf,
|
|
23
|
-
getExifData: () => getExifData,
|
|
24
23
|
group: () => group,
|
|
25
24
|
http: () => http,
|
|
26
25
|
lastReferenceValue: () => lastReferenceValue,
|
|
@@ -93,7 +92,7 @@ function embedImageMetadata(inputBuffer, kvPairs) {
|
|
|
93
92
|
return { buffer: injectExif(inputBuffer, kvPairs) };
|
|
94
93
|
}
|
|
95
94
|
async function compressImage(inputBuffer, options = {}) {
|
|
96
|
-
const { maxBytes
|
|
95
|
+
const { maxBytes, minQuality } = options;
|
|
97
96
|
const kb = (n) => `${(n / 1024).toFixed(1)}KB`;
|
|
98
97
|
const image = await Jimp.read(inputBuffer);
|
|
99
98
|
let quality = 80;
|
|
@@ -205,6 +204,7 @@ function compress(base64ImgOrBuffer, options = {}) {
|
|
|
205
204
|
base64ImgOrBuffer,
|
|
206
205
|
options
|
|
207
206
|
);
|
|
207
|
+
const { maxBytes = 700 * 1024, minQuality = 20 } = resolvedOptions;
|
|
208
208
|
const result = await compressImage(
|
|
209
209
|
resolveInput(resolvedImg),
|
|
210
210
|
resolvedOptions
|
|
@@ -269,7 +269,6 @@ export {
|
|
|
269
269
|
fields,
|
|
270
270
|
fn,
|
|
271
271
|
fnIf,
|
|
272
|
-
getExifData,
|
|
273
272
|
group,
|
|
274
273
|
http,
|
|
275
274
|
lastReferenceValue,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-image-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "OpenFn image-utils adaptor",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"jimp": "^1.6.0",
|
|
24
24
|
"piexifjs": "^1.0.6",
|
|
25
|
-
"@openfn/language-common": "3.3.
|
|
25
|
+
"@openfn/language-common": "3.3.5"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"assertion-error": "2.0.0",
|
|
29
29
|
"chai": "4.3.6",
|
|
30
30
|
"deep-eql": "4.1.1",
|
|
31
|
-
"mocha": "^10.7.3",
|
|
32
31
|
"rimraf": "3.0.2"
|
|
33
32
|
},
|
|
34
33
|
"repository": {
|
|
@@ -44,7 +43,6 @@
|
|
|
44
43
|
"test:integration": "mocha --experimental-specifier-resolution=node --no-warnings test/integration.js",
|
|
45
44
|
"clean": "rimraf dist types docs",
|
|
46
45
|
"pack": "pnpm pack --pack-destination ../../dist",
|
|
47
|
-
"lint": "eslint src"
|
|
48
|
-
"benchmark": "echo 'benchmark removed — jsquash dependency dropped'"
|
|
46
|
+
"lint": "eslint src"
|
|
49
47
|
}
|
|
50
48
|
}
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
/**
|
|
9
9
|
* Resize an image to the given dimensions.
|
|
10
10
|
* Writes `{ buffer, width, height }` to `state.data`.
|
|
11
|
+
* @public
|
|
11
12
|
* @example
|
|
12
|
-
* resize(
|
|
13
|
+
* resize($.data.photoBase64, { width: 1200, height: 1600 })
|
|
13
14
|
* @function
|
|
14
15
|
* @param {string|Buffer|Function} base64ImgOrBuffer - Base64 string, data URL, Buffer, or resolver fn
|
|
15
16
|
* @param {object} [options={}]
|
|
@@ -27,6 +28,7 @@ export function resize(base64ImgOrBuffer: string | Buffer | Function, options?:
|
|
|
27
28
|
/**
|
|
28
29
|
* Compress an image by reducing image quality until it reaches the criteria.
|
|
29
30
|
* Writes `{ buffer, size, quality }` to `state.data`.
|
|
31
|
+
* @public
|
|
30
32
|
* @example
|
|
31
33
|
* compress(state.data.buffer, { maxBytes: 700 * 1024, minQuality: 20 })
|
|
32
34
|
* @function
|
|
@@ -46,8 +48,9 @@ export function compress(base64ImgOrBuffer: string | Buffer | Function, options?
|
|
|
46
48
|
/**
|
|
47
49
|
* Strip all EXIF metadata from an image. Output is always a JPEG buffer.
|
|
48
50
|
* Writes `{ buffer }` to `state.data`.
|
|
51
|
+
* @public
|
|
49
52
|
* @example
|
|
50
|
-
* stripMetadata(
|
|
53
|
+
* stripMetadata($.data.photoBase64)
|
|
51
54
|
* @function
|
|
52
55
|
* @param {string|Buffer|Function} base64ImgOrBuffer - Base64 string, data URL, Buffer, or resolver fn
|
|
53
56
|
* @param {object} [options={}]
|
|
@@ -61,9 +64,10 @@ export function stripMetadata(base64ImgOrBuffer: string | Buffer | Function, opt
|
|
|
61
64
|
/**
|
|
62
65
|
* Embed EXIF metadata into a JPEG image.
|
|
63
66
|
* Writes `{ buffer }` to `state.data`.
|
|
67
|
+
* @public
|
|
64
68
|
* @example
|
|
65
|
-
* embedMetadata(
|
|
66
|
-
* embedMetadata(
|
|
69
|
+
* embedMetadata($.data.buffer, { UserComment: 'patient-id=42' })
|
|
70
|
+
* embedMetadata($.data.buffer, { UserComment: 'patient-id=42', Make: 'OpenFn' }, { parseAs: 'base64' })
|
|
67
71
|
* @function
|
|
68
72
|
* @param {string|Buffer|Function} base64ImgOrBuffer - Base64 string, data URL, Buffer, or resolver fn
|
|
69
73
|
* @param {object} exifObj - EXIF key-value pairs; keys must be valid EXIF tag names (e.g. UserComment, Make, Model)
|
|
@@ -80,8 +84,9 @@ export function embedMetadata(base64ImgOrBuffer: string | Buffer | Function, exi
|
|
|
80
84
|
* Writes `{ width, height, orientation, size, exif }` to `state.data`.
|
|
81
85
|
* `exif` is a flat object of human-readable EXIF tag names (e.g. `{ Make, Model, GPSLatitude, UserComment }`).
|
|
82
86
|
* `UserComment` has the `ASCII\0\0\0` encoding prefix stripped. Images with no EXIF return `exif: {}`.
|
|
87
|
+
* @public
|
|
83
88
|
* @example
|
|
84
|
-
* metadata(
|
|
89
|
+
* metadata($.data.photoBase64)
|
|
85
90
|
* fn(state => {
|
|
86
91
|
* if (state.data.size > 700 * 1024) { ... }
|
|
87
92
|
* return state;
|
|
@@ -92,7 +97,6 @@ export function embedMetadata(base64ImgOrBuffer: string | Buffer | Function, exi
|
|
|
92
97
|
* @returns {Operation}
|
|
93
98
|
*/
|
|
94
99
|
export function metadata(base64ImgOrBuffer: string | Buffer | Function): Operation;
|
|
95
|
-
export { getExifData };
|
|
96
100
|
/**
|
|
97
101
|
* State object
|
|
98
102
|
*/
|
|
@@ -106,5 +110,4 @@ export type ImageState = {
|
|
|
106
110
|
*/
|
|
107
111
|
references: any;
|
|
108
112
|
};
|
|
109
|
-
import { getExifData } from "./Utils.js";
|
|
110
113
|
export { as, combine, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, group, lastReferenceValue, map, merge, scrubEmojis, sourceValue, util, http } from "@openfn/language-common";
|