drp-imagesdk 2.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/LICENSE +21 -0
- package/README.md +665 -0
- package/dist/adjustments.d.ts +3 -0
- package/dist/adjustments.d.ts.map +1 -0
- package/dist/adjustments.js +57 -0
- package/dist/adjustments.js.map +1 -0
- package/dist/batch.d.ts +27 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/batch.js +99 -0
- package/dist/batch.js.map +1 -0
- package/dist/compress.d.ts +11 -0
- package/dist/compress.d.ts.map +1 -0
- package/dist/compress.js +273 -0
- package/dist/compress.js.map +1 -0
- package/dist/convert.d.ts +8 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +116 -0
- package/dist/convert.js.map +1 -0
- package/dist/crop.d.ts +4 -0
- package/dist/crop.d.ts.map +1 -0
- package/dist/crop.js +32 -0
- package/dist/crop.js.map +1 -0
- package/dist/drp-class.d.ts +58 -0
- package/dist/drp-class.d.ts.map +1 -0
- package/dist/drp-class.js +191 -0
- package/dist/drp-class.js.map +1 -0
- package/dist/drp.d.ts +14 -0
- package/dist/drp.d.ts.map +1 -0
- package/dist/drp.js +23 -0
- package/dist/drp.js.map +1 -0
- package/dist/editor.d.ts +24 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +153 -0
- package/dist/editor.js.map +1 -0
- package/dist/filters.d.ts +19 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +207 -0
- package/dist/filters.js.map +1 -0
- package/dist/image-sdk.iife.js +1979 -0
- package/dist/image-sdk.iife.js.map +1 -0
- package/dist/image-sdk.min.js +1978 -0
- package/dist/image-sdk.umd.js +1980 -0
- package/dist/image-sdk.umd.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/layers.d.ts +12 -0
- package/dist/layers.d.ts.map +1 -0
- package/dist/layers.js +174 -0
- package/dist/layers.js.map +1 -0
- package/dist/loader.d.ts +10 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +114 -0
- package/dist/loader.js.map +1 -0
- package/dist/metadata.d.ts +6 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +127 -0
- package/dist/metadata.js.map +1 -0
- package/dist/presets.d.ts +11 -0
- package/dist/presets.d.ts.map +1 -0
- package/dist/presets.js +28 -0
- package/dist/presets.js.map +1 -0
- package/dist/resize.d.ts +4 -0
- package/dist/resize.d.ts.map +1 -0
- package/dist/resize.js +68 -0
- package/dist/resize.js.map +1 -0
- package/dist/transform.d.ts +6 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +94 -0
- package/dist/transform.js.map +1 -0
- package/dist/types.d.ts +153 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/worker.d.ts +8 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +124 -0
- package/dist/worker.js.map +1 -0
- package/dist/zoom.d.ts +14 -0
- package/dist/zoom.d.ts.map +1 -0
- package/dist/zoom.js +55 -0
- package/dist/zoom.js.map +1 -0
- package/package.json +92 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Darpan Adhikari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
# DRP
|
|
2
|
+
|
|
3
|
+
**One line. Any combination. Image processing for JavaScript.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/drp-imagesdk)
|
|
6
|
+
[](https://github.com/DarpanAdhikari/image-conversions/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
DRP (Digital Resolution Pro) is a single-method image SDK. Pass any combination of options — format, compression, resize, crop, filter, rotate — and the pipeline builds itself.
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { DRP } from 'drp-imagesdk';
|
|
12
|
+
|
|
13
|
+
const result = await DRP(file, {
|
|
14
|
+
format: 'webp',
|
|
15
|
+
targetSize: '500KB',
|
|
16
|
+
width: 800,
|
|
17
|
+
filter: 'vintage',
|
|
18
|
+
});
|
|
19
|
+
// result.blob — processed image ready to use
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
No chains. No config. Just `DRP()`.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Table of Contents
|
|
27
|
+
|
|
28
|
+
- [Install](#install)
|
|
29
|
+
- [Quick Start](#quick-start)
|
|
30
|
+
- [Why DRP](#why-drp)
|
|
31
|
+
- [Recipes](#recipes)
|
|
32
|
+
- [DRP Options](#drp-options)
|
|
33
|
+
- [Static Methods](#static-methods)
|
|
34
|
+
- [Compression](#compression)
|
|
35
|
+
- [Editor](#editor)
|
|
36
|
+
- [Filters](#filters)
|
|
37
|
+
- [Batch Processing](#batch-processing)
|
|
38
|
+
- [Export Presets](#export-presets)
|
|
39
|
+
- [Modular Imports](#modular-imports)
|
|
40
|
+
- [Supported Formats](#supported-formats)
|
|
41
|
+
- [Browser Support](#browser-support)
|
|
42
|
+
- [Development](#development)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm install drp-imagesdk
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or use a CDN:
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<script src="https://unpkg.com/drp-imagesdk/dist/image-sdk.min.js"></script>
|
|
57
|
+
<script>
|
|
58
|
+
// Available globally as window.DRP
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { DRP } from 'drp-imagesdk';
|
|
68
|
+
|
|
69
|
+
// 1. Read any source
|
|
70
|
+
const result = await DRP(file); // File, Blob, URL string, HTMLImageElement, or canvas
|
|
71
|
+
|
|
72
|
+
// 2. Add any options
|
|
73
|
+
const result = await DRP(file, {
|
|
74
|
+
format: 'webp', // convert
|
|
75
|
+
width: 800, // resize
|
|
76
|
+
rotate: 90, // rotate
|
|
77
|
+
filter: 'warm', // filter
|
|
78
|
+
quality: 85, // quality
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// 3. Use the result
|
|
82
|
+
const url = URL.createObjectURL(result.blob);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The pipeline runs automatically: **load → crop → resize → rotate → flip → adjustments → filter → encode → metadata**. You only specify what you need.
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Why DRP
|
|
90
|
+
|
|
91
|
+
**One method, not twenty.** Every operation goes through `DRP()`. No need to learn separate functions for resize, crop, convert, compress.
|
|
92
|
+
|
|
93
|
+
**Any combination.** Mix resize + convert + filter + compress in one call. The order is always correct.
|
|
94
|
+
|
|
95
|
+
**Target size compression.** Say `targetSize: '500KB'` and DRP uses binary search to hit your file size goal — automatically.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Recipes
|
|
100
|
+
|
|
101
|
+
### I want to resize an image
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const result = await DRP(file, { width: 800 });
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### I want to convert to WebP
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
const result = await DRP(file, { format: 'webp', quality: 85 });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### I want to compress to a specific file size
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const result = await DRP(file, { targetSize: '200KB' });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### I want to crop and resize
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const result = await DRP(file, {
|
|
123
|
+
crop: { x: 100, y: 50, width: 400, height: 300 },
|
|
124
|
+
width: 800,
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### I want to rotate and flip
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const result = await DRP(file, { rotate: 90, flip: 'horizontal' });
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### I want to apply a filter
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const result = await DRP(file, { filter: 'cinematic' });
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### I want to resize and compress for web
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
const result = await DRP(file, {
|
|
144
|
+
width: 1200,
|
|
145
|
+
format: 'webp',
|
|
146
|
+
targetSize: '300KB',
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### I want to do everything at once
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const result = await DRP(file, {
|
|
154
|
+
crop: { x: 0, y: 0, width: 500, height: 500 },
|
|
155
|
+
width: 400,
|
|
156
|
+
height: 400,
|
|
157
|
+
rotate: 180,
|
|
158
|
+
flip: 'horizontal',
|
|
159
|
+
filter: 'vintage',
|
|
160
|
+
adjustments: { brightness: 10, contrast: 15 },
|
|
161
|
+
format: 'webp',
|
|
162
|
+
quality: 90,
|
|
163
|
+
metadata: { preserve: true },
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## DRP Options
|
|
170
|
+
|
|
171
|
+
All options are optional. Pass only what you need.
|
|
172
|
+
|
|
173
|
+
| Option | Type | Default | Description |
|
|
174
|
+
|--------|------|---------|-------------|
|
|
175
|
+
| `format` | `'jpeg' \| 'png' \| 'webp' \| 'avif' \| 'gif' \| 'bmp'` | `'webp'` | Output format |
|
|
176
|
+
| `quality` | `number` | `80` | Quality 1–100 (JPEG/WebP/AVIF) |
|
|
177
|
+
| `targetSize` | `string \| number` | — | Target file size. String: `'500KB'`, `'2MB'`. Number: bytes |
|
|
178
|
+
| `tolerance` | `number` | `10` | Target size tolerance % |
|
|
179
|
+
| `width` | `number` | — | Target width in pixels |
|
|
180
|
+
| `height` | `number` | — | Target height in pixels |
|
|
181
|
+
| `maintainAspectRatio` | `boolean` | `true` | Keep aspect ratio when resizing |
|
|
182
|
+
| `crop` | `{ x, y, width, height }` | — | Crop region (pixels from top-left) |
|
|
183
|
+
| `rotate` | `number` | — | Rotation in degrees |
|
|
184
|
+
| `flip` | `'horizontal' \| 'vertical' \| 'both'` | — | Flip direction |
|
|
185
|
+
| `filter` | `FilterPreset` | — | Filter preset name (see [Filters](#filters)) |
|
|
186
|
+
| `adjustments` | `Adjustments` | — | Color/tone adjustments (see below) |
|
|
187
|
+
| `metadata` | `{ preserve?, remove?, custom? }` | — | Metadata handling |
|
|
188
|
+
| `onProgress` | `(event) => void` | — | Progress callback |
|
|
189
|
+
|
|
190
|
+
### Adjustments
|
|
191
|
+
|
|
192
|
+
| Property | Type | Range | Description |
|
|
193
|
+
|----------|------|-------|-------------|
|
|
194
|
+
| `brightness` | `number` | -100 to 100 | Brightness |
|
|
195
|
+
| `contrast` | `number` | -100 to 100 | Contrast |
|
|
196
|
+
| `saturation` | `number` | -100 to 100 | Color saturation |
|
|
197
|
+
| `temperature` | `number` | -100 to 100 | Warm/cool shift |
|
|
198
|
+
| `tint` | `number` | -100 to 100 | Green/magenta shift |
|
|
199
|
+
| `exposure` | `number` | -100 to 100 | Exposure |
|
|
200
|
+
| `highlights` | `number` | -100 to 100 | Highlight recovery |
|
|
201
|
+
| `shadows` | `number` | -100 to 100 | Shadow recovery |
|
|
202
|
+
| `sharpness` | `number` | 0 to 100 | Sharpness |
|
|
203
|
+
| `blur` | `number` | 0 to 20 | Blur radius |
|
|
204
|
+
| `opacity` | `number` | 0 to 100 | Opacity |
|
|
205
|
+
| `grayscale` | `boolean` | — | Convert to grayscale |
|
|
206
|
+
| `sepia` | `boolean` | — | Apply sepia tone |
|
|
207
|
+
|
|
208
|
+
### Metadata Options
|
|
209
|
+
|
|
210
|
+
| Property | Type | Description |
|
|
211
|
+
|----------|------|-------------|
|
|
212
|
+
| `preserve` | `boolean` | Preserve existing EXIF/metadata |
|
|
213
|
+
| `remove` | `boolean` | Strip all metadata |
|
|
214
|
+
| `custom` | `Record<string, unknown>` | Embed custom key-value metadata |
|
|
215
|
+
|
|
216
|
+
### DRP Result
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
interface DRPResult {
|
|
220
|
+
blob: Blob; // Processed image
|
|
221
|
+
size: number; // Output file size in bytes
|
|
222
|
+
format: string; // Output format used
|
|
223
|
+
quality: number; // Quality applied
|
|
224
|
+
width: number; // Output width
|
|
225
|
+
height: number; // Output height
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Static Methods
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { DRP } from 'drp-imagesdk';
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### `DRP.editor(source)`
|
|
238
|
+
|
|
239
|
+
Creates a full editor instance with undo/redo, layers, and interactive editing.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
const editor = await DRP.editor(file);
|
|
243
|
+
|
|
244
|
+
editor.crop({ x: 0, y: 0, width: 400, height: 300 });
|
|
245
|
+
editor.resize({ width: 800 });
|
|
246
|
+
editor.adjust({ brightness: 20, contrast: 10 });
|
|
247
|
+
editor.applyFilter('cinematic');
|
|
248
|
+
|
|
249
|
+
const blob = await editor.export({ format: 'png' });
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### `DRP.batch(files, operation, onProgress?)`
|
|
253
|
+
|
|
254
|
+
Process multiple files at once.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
const results = await DRP.batch(files, {
|
|
258
|
+
type: 'resize',
|
|
259
|
+
options: { width: 800 },
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// results: Array<{ blob, file, success, error? }>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `DRP.validate(file, maxSize?)`
|
|
266
|
+
|
|
267
|
+
Check if a file meets size requirements.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const result = DRP.validate(file, 5 * 1024 * 1024); // 5MB limit
|
|
271
|
+
// result: { valid: boolean, size: number, maxSize?: number, message: string }
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### `DRP.preview(source, format?)`
|
|
275
|
+
|
|
276
|
+
Get compression estimates before processing.
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const preview = await DRP.preview(file, 'jpeg');
|
|
280
|
+
// preview: { originalSize, estimatedSize, estimatedSavingsPercent, recommendedFormat, recommendedQuality }
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### `DRP.readMetadata(source)`
|
|
284
|
+
|
|
285
|
+
Read EXIF and metadata from an image.
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
const metadata = await DRP.readMetadata(file);
|
|
289
|
+
// metadata: { exif?, xmp?, custom? }
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### `DRP.version()`
|
|
293
|
+
|
|
294
|
+
Returns the SDK version string.
|
|
295
|
+
|
|
296
|
+
### `DRP.formats()`
|
|
297
|
+
|
|
298
|
+
Returns supported format list: `['jpeg', 'png', 'webp', 'avif', 'gif', 'bmp']`
|
|
299
|
+
|
|
300
|
+
### `DRP.filters()`
|
|
301
|
+
|
|
302
|
+
Returns available filter presets: `['original', 'vintage', 'blackAndWhite', ...]`
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Compression
|
|
307
|
+
|
|
308
|
+
DRP uses binary search over quality levels to hit your target file size — automatically.
|
|
309
|
+
|
|
310
|
+
### Target Size
|
|
311
|
+
|
|
312
|
+
```typescript
|
|
313
|
+
// String format
|
|
314
|
+
const result = await DRP(file, { targetSize: '500KB' });
|
|
315
|
+
const result = await DRP(file, { targetSize: '2MB' });
|
|
316
|
+
|
|
317
|
+
// Bytes
|
|
318
|
+
const result = await DRP(file, { targetSize: 512000 });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Compression Presets
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
import { smartCompress } from 'drp-imagesdk';
|
|
325
|
+
|
|
326
|
+
const result = await smartCompress(file, 'web'); // Web-optimized
|
|
327
|
+
const result = await smartCompress(file, 'email'); // Email-friendly
|
|
328
|
+
const result = await smartCompress(file, 'print'); // Print quality
|
|
329
|
+
const result = await smartCompress(file, 'thumbnail'); // Thumbnail
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
| Preset | Format | Quality | Max Dimension | Target Size |
|
|
333
|
+
|--------|--------|---------|---------------|-------------|
|
|
334
|
+
| `web` | WebP | 75 | 1920px | 500 KB |
|
|
335
|
+
| `email` | JPEG | 70 | 800px | 1 MB |
|
|
336
|
+
| `print` | JPEG | 95 | 3000px | — |
|
|
337
|
+
| `thumbnail` | WebP | 60 | 400px | 100 KB |
|
|
338
|
+
|
|
339
|
+
### Preview Before Compressing
|
|
340
|
+
|
|
341
|
+
```typescript
|
|
342
|
+
import { getCompressionPreview } from 'drp-imagesdk';
|
|
343
|
+
|
|
344
|
+
const preview = await getCompressionPreview(file, 'webp');
|
|
345
|
+
console.log(preview.originalSize); // 2.4 MB
|
|
346
|
+
console.log(preview.estimatedSize); // ~180 KB
|
|
347
|
+
console.log(preview.estimatedSavingsPercent); // 92%
|
|
348
|
+
console.log(preview.recommendedFormat); // 'webp'
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Editor
|
|
354
|
+
|
|
355
|
+
The editor provides non-destructive editing with full undo/redo history and layer support.
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
const editor = await DRP.editor(file);
|
|
359
|
+
|
|
360
|
+
// Transform
|
|
361
|
+
editor.crop({ x: 50, y: 50, width: 400, height: 300 });
|
|
362
|
+
editor.resize({ width: 800, maintainAspectRatio: true });
|
|
363
|
+
editor.rotate({ degrees: 45 });
|
|
364
|
+
editor.flip({ horizontal: true });
|
|
365
|
+
|
|
366
|
+
// Adjust
|
|
367
|
+
editor.adjust({ brightness: 20, contrast: 10, saturation: -15 });
|
|
368
|
+
editor.applyFilter('vintage');
|
|
369
|
+
|
|
370
|
+
// Layers
|
|
371
|
+
import { createTextLayer, createShapeLayer } from 'drp-imagesdk';
|
|
372
|
+
|
|
373
|
+
editor.addLayer(createTextLayer({
|
|
374
|
+
content: 'Hello World',
|
|
375
|
+
fontSize: 48,
|
|
376
|
+
color: '#ffffff',
|
|
377
|
+
x: 50,
|
|
378
|
+
y: 50,
|
|
379
|
+
}));
|
|
380
|
+
|
|
381
|
+
editor.addLayer(createShapeLayer({
|
|
382
|
+
shapeType: 'rectangle',
|
|
383
|
+
fill: '#3b82f6',
|
|
384
|
+
x: 100,
|
|
385
|
+
y: 100,
|
|
386
|
+
width: 200,
|
|
387
|
+
height: 100,
|
|
388
|
+
}));
|
|
389
|
+
|
|
390
|
+
// Undo/Redo
|
|
391
|
+
editor.undo();
|
|
392
|
+
editor.redo();
|
|
393
|
+
editor.reset();
|
|
394
|
+
|
|
395
|
+
// Export
|
|
396
|
+
const blob = await editor.export({ format: 'png', quality: 90 });
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Compression from Editor
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
// Compress to target size from the editor
|
|
403
|
+
const blob = await editor.compress({
|
|
404
|
+
format: 'webp',
|
|
405
|
+
targetSize: '200KB',
|
|
406
|
+
quality: 80,
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Layer Types
|
|
411
|
+
|
|
412
|
+
| Factory | Type | Description |
|
|
413
|
+
|---------|------|-------------|
|
|
414
|
+
| `createTextLayer(options?)` | `TextLayer` | Text with font, size, color, alignment |
|
|
415
|
+
| `createShapeLayer(options?)` | `ShapeLayer` | Rectangle, circle, or line |
|
|
416
|
+
| `createImageLayer(img, options?)` | `ImageLayer` | Embedded image |
|
|
417
|
+
|
|
418
|
+
---
|
|
419
|
+
|
|
420
|
+
## Filters
|
|
421
|
+
|
|
422
|
+
```typescript
|
|
423
|
+
const result = await DRP(file, { filter: 'vintage' });
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
| Preset | Description |
|
|
427
|
+
|--------|-------------|
|
|
428
|
+
| `original` | No filter |
|
|
429
|
+
| `vintage` | Warm, faded vintage look |
|
|
430
|
+
| `blackAndWhite` | High-contrast black & white |
|
|
431
|
+
| `warm` | Warm color temperature |
|
|
432
|
+
| `cool` | Cool color temperature |
|
|
433
|
+
| `cinematic` | Movie-like color grading |
|
|
434
|
+
| `fade` | Low-contrast faded look |
|
|
435
|
+
| `dramatic` | High contrast, desaturated |
|
|
436
|
+
| `soft` | Soft, slightly blurred |
|
|
437
|
+
| `highContrast` | Increased contrast and punch |
|
|
438
|
+
|
|
439
|
+
List all filters programmatically:
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
import { AVAILABLE_FILTERS, getFilterName } from 'drp-imagesdk';
|
|
443
|
+
|
|
444
|
+
AVAILABLE_FILTERS.forEach((f) => {
|
|
445
|
+
console.log(`${f} → ${getFilterName(f)}`);
|
|
446
|
+
});
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
## Batch Processing
|
|
452
|
+
|
|
453
|
+
Process multiple files with a single operation.
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
import { DRP } from 'drp-imagesdk';
|
|
457
|
+
|
|
458
|
+
// Resize all files to 800px width
|
|
459
|
+
const results = await DRP.batch(files, {
|
|
460
|
+
type: 'resize',
|
|
461
|
+
options: { width: 800, maintainAspectRatio: true },
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Convert all to WebP
|
|
465
|
+
const results = await DRP.batch(files, {
|
|
466
|
+
type: 'convert',
|
|
467
|
+
options: { format: 'webp', quality: 85 },
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
// Compress all to target size
|
|
471
|
+
const results = await DRP.batch(files, {
|
|
472
|
+
type: 'compress',
|
|
473
|
+
options: { format: 'webp', targetSize: 200 * 1024 },
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// Apply filter to all
|
|
477
|
+
const results = await DRP.batch(files, {
|
|
478
|
+
type: 'filter',
|
|
479
|
+
options: { preset: 'cinematic' },
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Download Batch Results
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
import { downloadBatchResult, downloadAllBatchResults } from 'drp-imagesdk';
|
|
487
|
+
|
|
488
|
+
// Download one
|
|
489
|
+
downloadBatchResult(results[0]);
|
|
490
|
+
|
|
491
|
+
// Download all
|
|
492
|
+
await downloadAllBatchResults(results);
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
---
|
|
496
|
+
|
|
497
|
+
## Export Presets
|
|
498
|
+
|
|
499
|
+
Pre-configured dimensions for popular social media platforms.
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
import { EXPORT_PRESETS, getExportPreset, getPresetsByCategory } from 'drp-imagesdk';
|
|
503
|
+
|
|
504
|
+
// Get a specific preset
|
|
505
|
+
const preset = getExportPreset('instagram-post');
|
|
506
|
+
// { name: 'instagram-post', label: 'Instagram Post', width: 1080, height: 1080, category: 'Instagram' }
|
|
507
|
+
|
|
508
|
+
// Get all presets grouped by platform
|
|
509
|
+
const grouped = getPresetsByCategory();
|
|
510
|
+
// { Instagram: [...], Twitter: [...], Facebook: [...], YouTube: [...], ... }
|
|
511
|
+
|
|
512
|
+
// Use a preset with DRP
|
|
513
|
+
const preset = getExportPreset('youtube-thumbnail');
|
|
514
|
+
const result = await DRP(file, { width: preset.width, height: preset.height });
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
### Available Presets
|
|
518
|
+
|
|
519
|
+
| Platform | Preset Name | Dimensions |
|
|
520
|
+
|----------|-------------|------------|
|
|
521
|
+
| Instagram | `instagram-post` | 1080 × 1080 |
|
|
522
|
+
| Instagram | `instagram-story` | 1080 × 1920 |
|
|
523
|
+
| Instagram | `instagram-reel` | 1080 × 1920 |
|
|
524
|
+
| Twitter | `twitter-post` | 1200 × 675 |
|
|
525
|
+
| Twitter | `twitter-header` | 1500 × 500 |
|
|
526
|
+
| Facebook | `facebook-post` | 1200 × 630 |
|
|
527
|
+
| Facebook | `facebook-cover` | 820 × 312 |
|
|
528
|
+
| YouTube | `youtube-thumbnail` | 1280 × 720 |
|
|
529
|
+
| YouTube | `youtube-banner` | 2560 × 1440 |
|
|
530
|
+
| LinkedIn | `linkedin-post` | 1200 × 627 |
|
|
531
|
+
| LinkedIn | `linkedin-cover` | 1584 × 396 |
|
|
532
|
+
| Pinterest | `pinterest-pin` | 1000 × 1500 |
|
|
533
|
+
| TikTok | `tiktok` | 1080 × 1920 |
|
|
534
|
+
|
|
535
|
+
---
|
|
536
|
+
|
|
537
|
+
## Modular Imports
|
|
538
|
+
|
|
539
|
+
For tree-shaking or advanced use, import individual operations:
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
// Single operations
|
|
543
|
+
import { resizeImage, cropImage, rotateImage, flipImage } from 'drp-imagesdk';
|
|
544
|
+
import { convertImage, getSupportedFormats } from 'drp-imagesdk';
|
|
545
|
+
import { applyFilter, AVAILABLE_FILTERS } from 'drp-imagesdk';
|
|
546
|
+
import { compressToTargetSize, smartCompress, getCompressionPreview } from 'drp-imagesdk';
|
|
547
|
+
import { readMetadata, exportWithMetadata } from 'drp-imagesdk';
|
|
548
|
+
|
|
549
|
+
// Editor
|
|
550
|
+
import { createEditor } from 'drp-imagesdk';
|
|
551
|
+
|
|
552
|
+
// Batch
|
|
553
|
+
import { batchProcess } from 'drp-imagesdk';
|
|
554
|
+
|
|
555
|
+
// Layers
|
|
556
|
+
import { createTextLayer, createShapeLayer, createImageLayer } from 'drp-imagesdk';
|
|
557
|
+
|
|
558
|
+
// Types
|
|
559
|
+
import type { ImageFormat, FilterPreset, DRPOptions, DRPResult, Editor } from 'drp-imagesdk';
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
### Individual Operation Examples
|
|
563
|
+
|
|
564
|
+
```typescript
|
|
565
|
+
import { resizeImage, convertImage } from 'drp-imagesdk';
|
|
566
|
+
|
|
567
|
+
// Resize
|
|
568
|
+
const canvas = await resizeImage(file, { width: 800, maintainAspectRatio: true });
|
|
569
|
+
|
|
570
|
+
// Convert
|
|
571
|
+
const blob = await convertImage(file, { format: 'webp', quality: 85 });
|
|
572
|
+
|
|
573
|
+
// Chain operations manually
|
|
574
|
+
const resized = await resizeImage(file, { width: 400 });
|
|
575
|
+
const blob = await convertImage(resized, { format: 'jpeg', quality: 90 });
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
---
|
|
579
|
+
|
|
580
|
+
## Supported Formats
|
|
581
|
+
|
|
582
|
+
| Format | Read | Write | Quality Control | Metadata |
|
|
583
|
+
|--------|------|-------|-----------------|----------|
|
|
584
|
+
| JPEG | Yes | Yes | Yes | Yes |
|
|
585
|
+
| PNG | Yes | Yes | — | Yes |
|
|
586
|
+
| WebP | Yes | Yes | Yes | Yes |
|
|
587
|
+
| AVIF | Yes | Yes | Yes | Limited |
|
|
588
|
+
| GIF | Yes | Yes | — | Limited |
|
|
589
|
+
| BMP | Yes | Yes | — | Limited |
|
|
590
|
+
|
|
591
|
+
---
|
|
592
|
+
|
|
593
|
+
## Browser Support
|
|
594
|
+
|
|
595
|
+
DRP requires the Canvas API, supported in all modern browsers:
|
|
596
|
+
|
|
597
|
+
- Chrome 4+
|
|
598
|
+
- Firefox 2+
|
|
599
|
+
- Safari 3.1+
|
|
600
|
+
- Edge 12+
|
|
601
|
+
|
|
602
|
+
**Format-specific notes:**
|
|
603
|
+
- **WebP** — All modern browsers
|
|
604
|
+
- **AVIF** — Chrome 85+, Firefox 93+, Safari 16.4+
|
|
605
|
+
- **Worker processing** — Available when `Worker` and `OffscreenCanvas` are supported
|
|
606
|
+
|
|
607
|
+
---
|
|
608
|
+
|
|
609
|
+
## Development
|
|
610
|
+
|
|
611
|
+
This is a monorepo. The SDK is at `packages/image-sdk`, the demo site is at `apps/demo`.
|
|
612
|
+
|
|
613
|
+
### Setup
|
|
614
|
+
|
|
615
|
+
```bash
|
|
616
|
+
npm install
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### Commands
|
|
620
|
+
|
|
621
|
+
| Command | Description |
|
|
622
|
+
|---------|-------------|
|
|
623
|
+
| `npm run dev` | Start demo dev server |
|
|
624
|
+
| `npm run build` | Build all packages |
|
|
625
|
+
| `npm run build:sdk` | Build SDK only |
|
|
626
|
+
| `npm run build:demo` | Build demo only |
|
|
627
|
+
| `npm run test` | Run all tests |
|
|
628
|
+
| `npm run test:sdk` | Run SDK tests |
|
|
629
|
+
| `npm run lint` | Lint all packages |
|
|
630
|
+
|
|
631
|
+
### Project Structure
|
|
632
|
+
|
|
633
|
+
```
|
|
634
|
+
drp-imagesdk/
|
|
635
|
+
├── packages/
|
|
636
|
+
│ └── image-sdk/ # The SDK (drp-imagesdk on npm)
|
|
637
|
+
│ ├── src/
|
|
638
|
+
│ │ ├── index.ts # All exports
|
|
639
|
+
│ │ ├── drp-class.ts # DRP() single method
|
|
640
|
+
│ │ ├── compress.ts # Compression engine
|
|
641
|
+
│ │ ├── editor.ts # Editor with undo/redo
|
|
642
|
+
│ │ ├── batch.ts # Batch processing
|
|
643
|
+
│ │ ├── convert.ts # Format conversion
|
|
644
|
+
│ │ ├── resize.ts # Resize operations
|
|
645
|
+
│ │ ├── crop.ts # Crop operations
|
|
646
|
+
│ │ ├── transform.ts # Rotate & flip
|
|
647
|
+
│ │ ├── filters.ts # 10 filter presets
|
|
648
|
+
│ │ ├── adjustments.ts # Color/tone adjustments
|
|
649
|
+
│ │ ├── layers.ts # Text, shape, image layers
|
|
650
|
+
│ │ ├── metadata.ts # EXIF read & write
|
|
651
|
+
│ │ ├── presets.ts # Social media presets
|
|
652
|
+
│ │ ├── loader.ts # File validation & loading
|
|
653
|
+
│ │ ├── worker.ts # Web Worker processing
|
|
654
|
+
│ │ └── zoom.ts # Zoom & pan utilities
|
|
655
|
+
│ ├── rollup.config.js # UMD/IIFE bundle config
|
|
656
|
+
│ └── package.json
|
|
657
|
+
└── apps/
|
|
658
|
+
└── demo/ # Demo website (drp-imagesdk in action)
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
---
|
|
662
|
+
|
|
663
|
+
## License
|
|
664
|
+
|
|
665
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjustments.d.ts","sourceRoot":"","sources":["../src/adjustments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAE,WAAW,GACvB,iBAAiB,CA4EnB"}
|