@imagemagick/magick-wasm 0.0.5 → 0.0.9

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/magick-image.d.ts CHANGED
@@ -6,6 +6,7 @@ import { DistortMethod } from './distort-method';
6
6
  import { DistortSettings } from './settings/distort-settings';
7
7
  import { ErrorMetric } from './error-metric';
8
8
  import { EvaluateOperator } from './evaluate-operator';
9
+ import { FilterType } from './filter-type';
9
10
  import { Gravity } from './gravity';
10
11
  import { IImageProfile } from './profiles/image-profile';
11
12
  import { IMagickImageCollection } from './magick-image-collection';
@@ -18,6 +19,7 @@ import { OrientationType } from './orientation-type';
18
19
  import { Percentage } from './percentage';
19
20
  import { PixelChannel } from './pixel-channel';
20
21
  import { IPixelCollection } from './pixels/pixel-collection';
22
+ import { PixelInterpolateMethod } from './pixel-interpolate-method';
21
23
  import { Point } from './point';
22
24
  import { VirtualPixelMethod } from './virtual-pixel-method';
23
25
  export interface IMagickImage extends INativeInstance {
@@ -26,8 +28,10 @@ export interface IMagickImage extends INativeInstance {
26
28
  readonly channelCount: number;
27
29
  colorSpace: ColorSpace;
28
30
  depth: number;
31
+ filterType: FilterType;
29
32
  format: string;
30
33
  hasAlpha: boolean;
34
+ interpolate: PixelInterpolateMethod;
31
35
  readonly height: number;
32
36
  orientation: OrientationType;
33
37
  quality: number;
@@ -41,6 +45,8 @@ export interface IMagickImage extends INativeInstance {
41
45
  blur(radius: number, sigma: number): void;
42
46
  blur(radius: number, sigma: number, channels: Channels): void;
43
47
  channelOffset(pixelChannel: PixelChannel): number;
48
+ charcoal(): void;
49
+ charcoal(radius: number, sigma: number): void;
44
50
  clahe(xTiles: number, yTiles: number, numberBins: number, clipLimit: number): void;
45
51
  clahe(xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number): void;
46
52
  clone(func: (image: IMagickImage) => void): void;
@@ -93,9 +99,13 @@ export interface IMagickImage extends INativeInstance {
93
99
  level(blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
94
100
  level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage): void;
95
101
  level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
102
+ liquidRescale(geometry: MagickGeometry): void;
103
+ liquidRescale(width: number, height: number): void;
96
104
  modulate(brightness: Percentage): void;
97
105
  modulate(brightness: Percentage, saturation: Percentage): void;
98
106
  modulate(brightness: Percentage, saturation: Percentage, hue: Percentage): void;
107
+ oilPaint(): void;
108
+ oilPaint(radius: number): void;
99
109
  read(color: MagickColor, width: number, height: number): void;
100
110
  read(fileName: string, settings?: MagickReadSettings): void;
101
111
  read(array: Uint8Array, settings?: MagickReadSettings): void;
@@ -104,6 +114,7 @@ export interface IMagickImage extends INativeInstance {
104
114
  removeWriteMask(): void;
105
115
  resize(geometry: MagickGeometry): void;
106
116
  resize(width: number, height: number): void;
117
+ rotate(degrees: number): void;
107
118
  sharpen(): void;
108
119
  sharpen(radius: number, sigma: number): void;
109
120
  sharpen(radius: number, sigma: number, channels: Channels): void;
@@ -121,6 +132,13 @@ export interface IMagickImage extends INativeInstance {
121
132
  setArtifact(name: string, value: boolean): void;
122
133
  setWriteMask(image: IMagickImage): void;
123
134
  toString(): string;
135
+ trim(): void;
136
+ trim(...edges: Gravity[]): void;
137
+ trim(percentage: Percentage): void;
138
+ vignette(): void;
139
+ vignette(radius: number, sigma: number, x: number, y: number): void;
140
+ wave(): void;
141
+ wave(method: PixelInterpolateMethod, amplitude: number, length: number): void;
124
142
  write(func: (data: Uint8Array) => void, format?: MagickFormat): void;
125
143
  write(func: (data: Uint8Array) => Promise<void>, format?: MagickFormat): Promise<void>;
126
144
  writeToCanvas(canvas: HTMLCanvasElement): void;
@@ -136,10 +154,14 @@ export declare class MagickImage extends NativeInstance implements IMagickImage
136
154
  set colorSpace(value: ColorSpace);
137
155
  get depth(): number;
138
156
  set depth(value: number);
157
+ get filterType(): number;
158
+ set filterType(value: number);
139
159
  get format(): string;
140
160
  set format(value: string);
141
161
  get hasAlpha(): boolean;
142
162
  set hasAlpha(value: boolean);
163
+ get interpolate(): PixelInterpolateMethod;
164
+ set interpolate(value: PixelInterpolateMethod);
143
165
  get height(): number;
144
166
  get orientation(): OrientationType;
145
167
  set orientation(value: OrientationType);
@@ -156,6 +178,8 @@ export declare class MagickImage extends NativeInstance implements IMagickImage
156
178
  blur(radius: number, sigma: number): void;
157
179
  blur(radius: number, sigma: number, channels: Channels): void;
158
180
  channelOffset(pixelChannel: PixelChannel): number;
181
+ charcoal(): void;
182
+ charcoal(radius: number, sigma: number): void;
159
183
  clahe(xTiles: number, yTiles: number, numberBins: number, clipLimit: number): void;
160
184
  clahe(xTiles: Percentage, yTiles: Percentage, numberBins: number, clipLimit: number): void;
161
185
  clone(func: (image: IMagickImage) => void): void;
@@ -209,9 +233,13 @@ export declare class MagickImage extends NativeInstance implements IMagickImage
209
233
  level(blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
210
234
  level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage): void;
211
235
  level(channels: Channels, blackPoint: Percentage, whitePoint: Percentage, gamma: number): void;
236
+ liquidRescale(geometry: MagickGeometry): void;
237
+ liquidRescale(width: number, height: number): void;
212
238
  modulate(brightness: Percentage): void;
213
239
  modulate(brightness: Percentage, saturation: Percentage): void;
214
240
  modulate(brightness: Percentage, saturation: Percentage, hue: Percentage): void;
241
+ oilPaint(): void;
242
+ oilPaint(radius: number): void;
215
243
  read(color: MagickColor, width: number, height: number): void;
216
244
  read(fileName: string, settings?: MagickReadSettings): void;
217
245
  read(array: Uint8Array, settings?: MagickReadSettings): void;
@@ -220,6 +248,7 @@ export declare class MagickImage extends NativeInstance implements IMagickImage
220
248
  removeWriteMask(): void;
221
249
  resize(geometry: MagickGeometry): void;
222
250
  resize(width: number, height: number): void;
251
+ rotate(degrees: number): void;
223
252
  sharpen(): void;
224
253
  sharpen(radius: number, sigma: number): void;
225
254
  sharpen(radius: number, sigma: number, channels: Channels): void;
@@ -237,6 +266,13 @@ export declare class MagickImage extends NativeInstance implements IMagickImage
237
266
  setArtifact(name: string, value: boolean): void;
238
267
  setWriteMask(image: IMagickImage): void;
239
268
  toString: () => string;
269
+ trim(): void;
270
+ trim(...edges: Gravity[]): void;
271
+ trim(percentage: Percentage): void;
272
+ wave(): void;
273
+ wave(method: PixelInterpolateMethod, amplitude: number, length: number): void;
274
+ vignette(): void;
275
+ vignette(radius: number, sigma: number, x: number, y: number): void;
240
276
  write(func: (data: Uint8Array) => void, format?: MagickFormat): void;
241
277
  write(func: (data: Uint8Array) => Promise<void>, format?: MagickFormat): Promise<void>;
242
278
  writeToCanvas(canvas: HTMLCanvasElement): void;
package/magick-image.js CHANGED
@@ -12,6 +12,7 @@ const image_profile_1 = require("./profiles/image-profile");
12
12
  const magick_image_collection_1 = require("./magick-image-collection");
13
13
  const native_instance_1 = require("./internal/native-instance");
14
14
  const magick_color_1 = require("./magick-color");
15
+ const magick_error_1 = require("./magick-error");
15
16
  const magick_format_1 = require("./magick-format");
16
17
  const magick_geometry_1 = require("./magick-geometry");
17
18
  const magick_read_settings_1 = require("./settings/magick-read-settings");
@@ -24,6 +25,7 @@ const pointer_1 = require("./internal/pointer/pointer");
24
25
  const quantum_1 = require("./quantum");
25
26
  const string_info_1 = require("./internal/string-info");
26
27
  const string_1 = require("./internal/native/string");
28
+ const gravity_2 = require("./gravity");
27
29
  const array_1 = require("./internal/native/array");
28
30
  class MagickImage extends native_instance_1.NativeInstance {
29
31
  constructor(instance, settings) {
@@ -63,8 +65,10 @@ class MagickImage extends native_instance_1.NativeInstance {
63
65
  }
64
66
  get depth() { return image_magick_1.ImageMagick._api._MagickImage_Depth_Get(this._instance); }
65
67
  set depth(value) { image_magick_1.ImageMagick._api._MagickImage_Depth_Set(this._instance, value); }
66
- get format() { return string_1._createString(image_magick_1.ImageMagick._api._MagickImage_Format_Get(this._instance), ''); }
67
- set format(value) { string_1._withString(value, instance => image_magick_1.ImageMagick._api._MagickImage_Format_Set(this._instance, instance)); }
68
+ get filterType() { return image_magick_1.ImageMagick._api._MagickImage_FilterType_Get(this._instance); }
69
+ set filterType(value) { image_magick_1.ImageMagick._api._MagickImage_FilterType_Set(this._instance, value); }
70
+ get format() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickImage_Format_Get(this._instance), ''); }
71
+ set format(value) { (0, string_1._withString)(value, instance => image_magick_1.ImageMagick._api._MagickImage_Format_Set(this._instance, instance)); }
68
72
  get hasAlpha() {
69
73
  return exception_1.Exception.usePointer(exception => {
70
74
  return this.toBool(image_magick_1.ImageMagick._api._MagickImage_HasAlpha_Get(this._instance, exception));
@@ -77,6 +81,12 @@ class MagickImage extends native_instance_1.NativeInstance {
77
81
  image_magick_1.ImageMagick._api._MagickImage_HasAlpha_Set(this._instance, this.fromBool(value), exception);
78
82
  });
79
83
  }
84
+ get interpolate() {
85
+ return image_magick_1.ImageMagick._api._MagickImage_Interpolate_Get(this._instance);
86
+ }
87
+ set interpolate(value) {
88
+ image_magick_1.ImageMagick._api._MagickImage_Interpolate_Set(this._instance, value);
89
+ }
80
90
  get height() { return image_magick_1.ImageMagick._api._MagickImage_Height_Get(this._instance); }
81
91
  get orientation() { return image_magick_1.ImageMagick._api._MagickImage_Orientation_Get(this._instance); }
82
92
  set orientation(value) { image_magick_1.ImageMagick._api._MagickImage_Orientation_Set(this._instance, value); }
@@ -89,7 +99,7 @@ class MagickImage extends native_instance_1.NativeInstance {
89
99
  }
90
100
  get signature() {
91
101
  return exception_1.Exception.usePointer(exception => {
92
- return string_1._createString(image_magick_1.ImageMagick._api._MagickImage_Signature_Get(this._instance, exception));
102
+ return (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickImage_Signature_Get(this._instance, exception));
93
103
  });
94
104
  }
95
105
  get virtualPixelMethod() {
@@ -132,6 +142,14 @@ class MagickImage extends native_instance_1.NativeInstance {
132
142
  return -1;
133
143
  return image_magick_1.ImageMagick._api._MagickImage_ChannelOffset(this._instance, pixelChannel);
134
144
  }
145
+ charcoal(radiusOrUndefined, sigmaOrUndefined) {
146
+ const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined;
147
+ const sigma = sigmaOrUndefined === undefined ? 1 : sigmaOrUndefined;
148
+ exception_1.Exception.use(exception => {
149
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Charcoal(this._instance, radius, sigma, exception.ptr);
150
+ this._setInstance(instance, exception);
151
+ });
152
+ }
135
153
  clahe(xTiles, yTiles, numberBins, clipLimit) {
136
154
  exception_1.Exception.usePointer(exception => {
137
155
  const xTilesValue = xTiles instanceof percentage_1.Percentage ? xTiles.multiply(this.width) : xTiles;
@@ -266,7 +284,7 @@ class MagickImage extends native_instance_1.NativeInstance {
266
284
  distortArgs = [];
267
285
  }
268
286
  exception_1.Exception.use(exception => {
269
- array_1._withDoubleArray(distortArgs, (distortArgsPtr) => {
287
+ (0, array_1._withDoubleArray)(distortArgs, (distortArgsPtr) => {
270
288
  const instance = image_magick_1.ImageMagick._api._MagickImage_Distort(this._instance, method, bestFit, distortArgsPtr, distortArgs.length, exception.ptr);
271
289
  this._setInstance(instance, exception);
272
290
  });
@@ -284,12 +302,12 @@ class MagickImage extends native_instance_1.NativeInstance {
284
302
  }
285
303
  else if (valueOrPercentage !== undefined) {
286
304
  if (typeof valueOrPercentageOrOperator !== 'number')
287
- throw new Error();
305
+ throw new magick_error_1.MagickError('this should not happen');
288
306
  const geometry = operatorOrGeometry;
289
307
  const operator = valueOrPercentageOrOperator;
290
308
  const value = typeof valueOrPercentage === 'number' ? valueOrPercentage : valueOrPercentage.toQuantum();
291
309
  if (geometry.isPercentage)
292
- throw new Error('percentage is not supported');
310
+ throw new magick_error_1.MagickError('percentage is not supported');
293
311
  exception_1.Exception.usePointer(exception => {
294
312
  magick_rectangle_1.MagickRectangle.use(this, geometry, rectangle => {
295
313
  image_magick_1.ImageMagick._api._MagickImage_EvaluateGeometry(this._instance, channels, rectangle, operator, value, exception);
@@ -313,20 +331,20 @@ class MagickImage extends native_instance_1.NativeInstance {
313
331
  else if (backgroundColorOrGravity !== undefined)
314
332
  gravity = backgroundColorOrGravity;
315
333
  exception_1.Exception.use(exception => {
316
- string_1._withString(geometry.toString(), geometryPtr => {
334
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
317
335
  const instance = image_magick_1.ImageMagick._api._MagickImage_Extent(this._instance, geometryPtr, gravity, exception.ptr);
318
336
  this._setInstance(instance, exception);
319
337
  });
320
338
  });
321
339
  }
322
340
  getArtifact(name) {
323
- return string_1._withString(name, namePtr => {
341
+ return (0, string_1._withString)(name, namePtr => {
324
342
  const value = image_magick_1.ImageMagick._api._MagickImage_GetArtifact(this._instance, namePtr);
325
- return string_1._createString(value);
343
+ return (0, string_1._createString)(value);
326
344
  });
327
345
  }
328
346
  getProfile(name) {
329
- return string_1._withString(name, namePtr => {
347
+ return (0, string_1._withString)(name, namePtr => {
330
348
  const value = image_magick_1.ImageMagick._api._MagickImage_GetProfile(this._instance, namePtr);
331
349
  const data = string_info_1.StringInfo.toArray(value);
332
350
  if (data === null)
@@ -367,24 +385,41 @@ class MagickImage extends native_instance_1.NativeInstance {
367
385
  image_magick_1.ImageMagick._api._MagickImage_Level(this._instance, blackPoint.toDouble(), whitePoint.toQuantum(), gammaValue, channels, exception);
368
386
  });
369
387
  }
388
+ liquidRescale(widthOrGeometry, height) {
389
+ const geometry = typeof widthOrGeometry === 'number' ? new magick_geometry_1.MagickGeometry(widthOrGeometry, height) : widthOrGeometry;
390
+ exception_1.Exception.use(exception => {
391
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
392
+ const instance = image_magick_1.ImageMagick._api._MagickImage_LiquidRescale(this._instance, geometryPtr, geometry.x, geometry.y, exception.ptr);
393
+ this._setInstance(instance, exception);
394
+ });
395
+ });
396
+ }
370
397
  modulate(brightness, saturation, hue) {
371
398
  const saturationPercentage = saturation === undefined ? new percentage_1.Percentage(100) : saturation;
372
399
  const huePercentage = hue === undefined ? new percentage_1.Percentage(100) : hue;
373
400
  exception_1.Exception.usePointer(exception => {
374
401
  const modulate = `${brightness.toDouble()}/${saturationPercentage.toDouble()}/${huePercentage.toDouble()}`;
375
- string_1._withString(modulate, modulatePtr => {
402
+ (0, string_1._withString)(modulate, modulatePtr => {
376
403
  image_magick_1.ImageMagick._api._MagickImage_Modulate(this._instance, modulatePtr, exception);
377
404
  });
378
405
  });
379
406
  }
407
+ oilPaint(radiusOrUndefined) {
408
+ const radius = radiusOrUndefined === undefined ? 3 : radiusOrUndefined;
409
+ const sigma = 0.0;
410
+ exception_1.Exception.use(exception => {
411
+ const instance = image_magick_1.ImageMagick._api._MagickImage_OilPaint(this._instance, radius, sigma, exception.ptr);
412
+ this._setInstance(instance, exception);
413
+ });
414
+ }
380
415
  read(fileNameOrArrayOrColor, settingsOrWidth, height) {
381
416
  exception_1.Exception.use(exception => {
382
417
  if (fileNameOrArrayOrColor instanceof Uint8Array) {
383
- const readSettings = settingsOrWidth instanceof magick_read_settings_1.MagickReadSettings ? settingsOrWidth : magick_read_settings_1.MagickReadSettings._createFrom(this._settings);
418
+ const readSettings = settingsOrWidth instanceof magick_read_settings_1.MagickReadSettings ? settingsOrWidth : new magick_read_settings_1.MagickReadSettings(this._settings);
384
419
  this.readFromArray(fileNameOrArrayOrColor, readSettings, exception);
385
420
  }
386
421
  else {
387
- const readSettings = settingsOrWidth instanceof magick_read_settings_1.MagickReadSettings ? settingsOrWidth : magick_read_settings_1.MagickReadSettings._createFrom(this._settings);
422
+ const readSettings = settingsOrWidth instanceof magick_read_settings_1.MagickReadSettings ? settingsOrWidth : new magick_read_settings_1.MagickReadSettings(this._settings);
388
423
  if (typeof fileNameOrArrayOrColor === 'string') {
389
424
  readSettings._fileName = fileNameOrArrayOrColor;
390
425
  }
@@ -414,7 +449,7 @@ class MagickImage extends native_instance_1.NativeInstance {
414
449
  });
415
450
  }
416
451
  removeArtifact(name) {
417
- string_1._withString(name, namePtr => {
452
+ (0, string_1._withString)(name, namePtr => {
418
453
  image_magick_1.ImageMagick._api._MagickImage_RemoveArtifact(this._instance, namePtr);
419
454
  });
420
455
  }
@@ -426,12 +461,18 @@ class MagickImage extends native_instance_1.NativeInstance {
426
461
  resize(widthOrGeometry, height) {
427
462
  const geometry = typeof widthOrGeometry === 'number' ? new magick_geometry_1.MagickGeometry(widthOrGeometry, height) : widthOrGeometry;
428
463
  exception_1.Exception.use(exception => {
429
- string_1._withString(geometry.toString(), geometryPtr => {
464
+ (0, string_1._withString)(geometry.toString(), geometryPtr => {
430
465
  const instance = image_magick_1.ImageMagick._api._MagickImage_Resize(this._instance, geometryPtr, exception.ptr);
431
466
  this._setInstance(instance, exception);
432
467
  });
433
468
  });
434
469
  }
470
+ rotate(degrees) {
471
+ exception_1.Exception.use(exception => {
472
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Rotate(this._instance, degrees, exception.ptr);
473
+ this._setInstance(instance, exception);
474
+ });
475
+ }
435
476
  sharpen(radius, sigma, channels) {
436
477
  const radiusValue = radius !== undefined ? radius : 0.0;
437
478
  const sigmaValue = sigma !== undefined ? sigma : 1.0;
@@ -492,8 +533,8 @@ class MagickImage extends native_instance_1.NativeInstance {
492
533
  else {
493
534
  strValue = this.fromBool(value).toString();
494
535
  }
495
- string_1._withString(name, namePtr => {
496
- string_1._withString(strValue, valuePtr => {
536
+ (0, string_1._withString)(name, namePtr => {
537
+ (0, string_1._withString)(strValue, valuePtr => {
497
538
  image_magick_1.ImageMagick._api._MagickImage_SetArtifact(this._instance, namePtr, valuePtr);
498
539
  });
499
540
  });
@@ -503,6 +544,44 @@ class MagickImage extends native_instance_1.NativeInstance {
503
544
  image_magick_1.ImageMagick._api._MagickImage_SetWriteMask(this._instance, image._instance, exception);
504
545
  });
505
546
  }
547
+ trim(...args) {
548
+ if (args.length > 0) {
549
+ if (args.length == 1 && args[0] instanceof percentage_1.Percentage) {
550
+ const percentage = args[0];
551
+ this.setArtifact('trim:percent-background', percentage.toDouble().toString());
552
+ }
553
+ else {
554
+ const edges = args;
555
+ const value = [...new Set((0, gravity_2._getEdges)(edges))].join(',');
556
+ this.setArtifact('trim:edges', value);
557
+ }
558
+ }
559
+ exception_1.Exception.use(exception => {
560
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Trim(this._instance, exception.ptr);
561
+ this._setInstance(instance, exception);
562
+ this.removeArtifact('trim:edges');
563
+ this.removeArtifact('trim:percent-background');
564
+ });
565
+ }
566
+ wave(methodOrUndefined, amplitudeOrUndefined, lengthOrUndefined) {
567
+ const method = methodOrUndefined == undefined ? this.interpolate : methodOrUndefined;
568
+ const amplitude = amplitudeOrUndefined == undefined ? 25 : amplitudeOrUndefined;
569
+ const length = lengthOrUndefined == undefined ? 150 : lengthOrUndefined;
570
+ exception_1.Exception.use(exception => {
571
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Wave(this._instance, method, amplitude, length, exception.ptr);
572
+ this._setInstance(instance, exception);
573
+ });
574
+ }
575
+ vignette(radiusOrUndefined, sigmaOrUndefined, xOrUndefined, yOrUndefined) {
576
+ const radius = radiusOrUndefined === undefined ? 0 : radiusOrUndefined;
577
+ const sigma = sigmaOrUndefined === undefined ? 1.0 : sigmaOrUndefined;
578
+ const x = xOrUndefined === undefined ? 0 : xOrUndefined;
579
+ const y = yOrUndefined === undefined ? 0 : yOrUndefined;
580
+ exception_1.Exception.use(exception => {
581
+ const instance = image_magick_1.ImageMagick._api._MagickImage_Vignette(this._instance, radius, sigma, x, y, exception.ptr);
582
+ this._setInstance(instance, exception);
583
+ });
584
+ }
506
585
  write(func, format) {
507
586
  let bytes = new Uint8Array();
508
587
  exception_1.Exception.use(exception => {
@@ -548,7 +627,7 @@ class MagickImage extends native_instance_1.NativeInstance {
548
627
  return new MagickImage(instance, settings);
549
628
  }
550
629
  _instanceNotInitialized() {
551
- throw new Error('no image has been read');
630
+ throw new magick_error_1.MagickError('no image has been read');
552
631
  }
553
632
  static _use(func) {
554
633
  const image = MagickImage.create();
package/magick.d.ts CHANGED
@@ -4,5 +4,6 @@ export declare class Magick {
4
4
  static get features(): string;
5
5
  static get imageMagickVersion(): string;
6
6
  static get supportedFormats(): MagickFormatInfo[];
7
+ static addFont(name: string, data: Uint8Array): void;
7
8
  static setRandomSeed: (seed: number) => void;
8
9
  }
package/magick.js CHANGED
@@ -5,10 +5,20 @@ const image_magick_1 = require("./image-magick");
5
5
  const magick_format_info_1 = require("./magick-format-info");
6
6
  const string_1 = require("./internal/native/string");
7
7
  class Magick {
8
- static get delegates() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_Delegates_Get(), 'Unknown'); }
9
- static get features() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_Features_Get(), ' ').slice(0, -1); }
10
- static get imageMagickVersion() { return string_1._createString(image_magick_1.ImageMagick._api._Magick_ImageMagickVersion_Get(), 'Unknown'); }
8
+ static get delegates() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_Delegates_Get(), 'Unknown'); }
9
+ static get features() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_Features_Get(), ' ').slice(0, -1); }
10
+ static get imageMagickVersion() { return (0, string_1._createString)(image_magick_1.ImageMagick._api._Magick_ImageMagickVersion_Get(), 'Unknown'); }
11
11
  static get supportedFormats() { return magick_format_info_1.MagickFormatInfo.all; }
12
+ static addFont(name, data) {
13
+ const fileSystem = image_magick_1.ImageMagick._api.FS;
14
+ const stats = fileSystem.analyzePath('/fonts');
15
+ if (!stats.exists) {
16
+ fileSystem.mkdir('/fonts');
17
+ }
18
+ const stream = fileSystem.open(`/fonts/${name}`, 'w+');
19
+ fileSystem.write(stream, data, 0, data.length);
20
+ fileSystem.close(stream);
21
+ }
12
22
  }
13
23
  exports.Magick = Magick;
14
24
  Magick.setRandomSeed = (seed) => image_magick_1.ImageMagick._api._Magick_SetRandomSeed(seed);
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "name": "@imagemagick/magick-wasm",
3
- "version": "0.0.5",
4
- "main": "image-magick.js",
5
- "description": "The WASM library for ImageMagick",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/dlemstra/Magick.WASM.git"
9
- },
10
- "author": "Dirk Lemstra",
11
- "license": "Apache-2.0",
12
- "bugs": {
13
- "url": "https://github.com/dlemstra/Magick.WASM/issues"
14
- },
15
- "homepage": "https://github.com/dlemstra/Magick.WASM",
16
- "keywords": ["imagemagick", "magick", "wasm", "image", "convert", "resize"]
2
+ "name": "@imagemagick/magick-wasm",
3
+ "version": "0.0.9",
4
+ "main": "image-magick.js",
5
+ "description": "The WASM library for ImageMagick",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/dlemstra/magick-wasm.git"
9
+ },
10
+ "author": "Dirk Lemstra",
11
+ "license": "Apache-2.0",
12
+ "bugs": {
13
+ "url": "https://github.com/dlemstra/magick-wasmissues"
14
+ },
15
+ "homepage": "https://github.com/dlemstra/magick-wasm",
16
+ "keywords": ["imagemagick", "magick", "wasm", "image", "convert", "resize"]
17
17
  }
@@ -0,0 +1,14 @@
1
+ export declare enum PixelInterpolateMethod {
2
+ Undefined = 0,
3
+ Average = 1,
4
+ Average9 = 2,
5
+ Average16 = 3,
6
+ Background = 4,
7
+ Bilinear = 5,
8
+ Blend = 6,
9
+ Catrom = 7,
10
+ Integer = 8,
11
+ Mesh = 9,
12
+ Nearest = 10,
13
+ Spline = 11
14
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PixelInterpolateMethod = void 0;
4
+ var PixelInterpolateMethod;
5
+ (function (PixelInterpolateMethod) {
6
+ PixelInterpolateMethod[PixelInterpolateMethod["Undefined"] = 0] = "Undefined";
7
+ PixelInterpolateMethod[PixelInterpolateMethod["Average"] = 1] = "Average";
8
+ PixelInterpolateMethod[PixelInterpolateMethod["Average9"] = 2] = "Average9";
9
+ PixelInterpolateMethod[PixelInterpolateMethod["Average16"] = 3] = "Average16";
10
+ PixelInterpolateMethod[PixelInterpolateMethod["Background"] = 4] = "Background";
11
+ PixelInterpolateMethod[PixelInterpolateMethod["Bilinear"] = 5] = "Bilinear";
12
+ PixelInterpolateMethod[PixelInterpolateMethod["Blend"] = 6] = "Blend";
13
+ PixelInterpolateMethod[PixelInterpolateMethod["Catrom"] = 7] = "Catrom";
14
+ PixelInterpolateMethod[PixelInterpolateMethod["Integer"] = 8] = "Integer";
15
+ PixelInterpolateMethod[PixelInterpolateMethod["Mesh"] = 9] = "Mesh";
16
+ PixelInterpolateMethod[PixelInterpolateMethod["Nearest"] = 10] = "Nearest";
17
+ PixelInterpolateMethod[PixelInterpolateMethod["Spline"] = 11] = "Spline";
18
+ })(PixelInterpolateMethod = exports.PixelInterpolateMethod || (exports.PixelInterpolateMethod = {}));
@@ -51,7 +51,7 @@ class PixelCollection extends native_instance_1.NativeInstance {
51
51
  setArea(x, y, width, height, quantumPixelsOrNumberPixels) {
52
52
  exception_1.Exception.usePointer(exception => {
53
53
  const pixels = (quantumPixelsOrNumberPixels instanceof Uint8Array) ? quantumPixelsOrNumberPixels : new Uint8Array(quantumPixelsOrNumberPixels);
54
- array_1._withQuantumArray(pixels, pixelsPtr => {
54
+ (0, array_1._withQuantumArray)(pixels, pixelsPtr => {
55
55
  image_magick_1.ImageMagick._api._PixelCollection_SetArea(this._instance, x, y, width, height, pixelsPtr, pixels.length, exception);
56
56
  });
57
57
  });
@@ -79,7 +79,7 @@ class PixelCollection extends native_instance_1.NativeInstance {
79
79
  }
80
80
  }
81
81
  use(x, y, width, height, mapping, func) {
82
- return string_1._withString(mapping, mappingPtr => {
82
+ return (0, string_1._withString)(mapping, mappingPtr => {
83
83
  return exception_1.Exception.use(exception => {
84
84
  const instance = image_magick_1.ImageMagick._api._PixelCollection_ToByteArray(this._instance, x, y, width, height, mappingPtr, exception.ptr);
85
85
  return exception.check(() => {
@@ -3,24 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MagickReadSettings = void 0;
4
4
  const image_magick_1 = require("../image-magick");
5
5
  const magick_settings_1 = require("./magick-settings");
6
- const magick_settings_2 = require("./magick-settings");
6
+ const native_magick_settings_1 = require("./native-magick-settings");
7
7
  const string_1 = require("../internal/native/string");
8
8
  class MagickReadSettings extends magick_settings_1.MagickSettings {
9
9
  constructor(partialSettings) {
10
10
  super();
11
11
  Object.assign(this, partialSettings);
12
12
  }
13
- static _createFrom(settings) {
14
- const result = new MagickReadSettings();
15
- result.format = settings.format;
16
- return result;
17
- }
18
13
  _use(func) {
19
- const settings = new magick_settings_2.NativeMagickSettings(this);
14
+ const settings = new native_magick_settings_1.NativeMagickSettings(this);
20
15
  try {
21
16
  const size = this.getSize();
22
17
  if (size !== '') {
23
- string_1._withString(size, sizePtr => {
18
+ (0, string_1._withString)(size, sizePtr => {
24
19
  image_magick_1.ImageMagick._api._MagickSettings_SetSize(settings._instance, sizePtr);
25
20
  });
26
21
  }
@@ -1,7 +1,14 @@
1
1
  import { IDefines } from '../defines/defines';
2
2
  import { MagickFormat } from '../magick-format';
3
+ import { MagickColor } from '../magick-color';
3
4
  export declare class MagickSettings {
5
+ backgroundColor?: MagickColor;
6
+ fillColor?: MagickColor;
7
+ font?: string;
8
+ fontPointsize?: number;
4
9
  format?: MagickFormat;
10
+ strokeColor?: MagickColor;
11
+ strokeWidth?: number;
5
12
  getDefine(name: string): string;
6
13
  getDefine(format: MagickFormat, name: string): string;
7
14
  setDefine(name: string, value: string): void;
@@ -9,5 +16,5 @@ export declare class MagickSettings {
9
16
  setDefine(format: MagickFormat, name: string, value: number): void;
10
17
  setDefine(format: MagickFormat, name: string, value: boolean): void;
11
18
  setDefines(defines: IDefines): void;
12
- parseDefine(format: MagickFormat, name: string): string;
19
+ private parseDefine;
13
20
  }
@@ -1,38 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MagickSettings = exports.NativeMagickSettings = void 0;
4
- const image_magick_1 = require("../image-magick");
3
+ exports.MagickSettings = void 0;
5
4
  const magick_format_1 = require("../magick-format");
6
- const native_instance_1 = require("../internal/native-instance");
7
- const string_1 = require("../internal/native/string");
8
- class NativeMagickSettings extends native_instance_1.NativeInstance {
9
- constructor(settings) {
10
- const instance = image_magick_1.ImageMagick._api._MagickSettings_Create();
11
- const disposeMethod = image_magick_1.ImageMagick._api._MagickSettings_Dispose;
12
- super(instance, disposeMethod);
13
- if (settings._fileName !== undefined) {
14
- string_1._withString(settings._fileName, filenamePtr => {
15
- image_magick_1.ImageMagick._api._MagickSettings_SetFileName(this._instance, filenamePtr);
16
- });
17
- }
18
- if (settings._quality !== undefined) {
19
- image_magick_1.ImageMagick._api._MagickSettings_SetQuality(this._instance, settings._quality);
20
- }
21
- if (settings.format !== undefined) {
22
- string_1._withString(settings.format, formatPtr => {
23
- image_magick_1.ImageMagick._api._MagickSettings_Format_Set(this._instance, formatPtr);
24
- });
25
- }
26
- for (const option in settings._options) {
27
- string_1._withString(option, optionPtr => {
28
- string_1._withString(settings._options[option], valuePtr => {
29
- image_magick_1.ImageMagick._api._MagickSettings_SetOption(this._instance, optionPtr, valuePtr);
30
- });
31
- });
32
- }
33
- }
34
- }
35
- exports.NativeMagickSettings = NativeMagickSettings;
5
+ const native_magick_settings_1 = require("./native-magick-settings");
36
6
  class MagickSettings {
37
7
  constructor() {
38
8
  this._options = {};
@@ -63,22 +33,13 @@ class MagickSettings {
63
33
  this.setDefine(define.format, define.name, define.value);
64
34
  });
65
35
  }
66
- parseDefine(format, name) {
67
- if (format === magick_format_1.MagickFormat.Unknown)
68
- return name;
69
- return `${format}:${name}`;
70
- }
71
36
  _clone() {
72
37
  const clone = new MagickSettings();
73
- clone._fileName = this._fileName;
74
- clone._quality = this._quality;
75
- clone.format = this.format;
76
- for (const option in this._options)
77
- clone._options[option] = this._options[option];
38
+ Object.assign(clone, this);
78
39
  return clone;
79
40
  }
80
41
  _use(func) {
81
- const settings = new NativeMagickSettings(this);
42
+ const settings = new native_magick_settings_1.NativeMagickSettings(this);
82
43
  try {
83
44
  return func(settings);
84
45
  }
@@ -86,5 +47,10 @@ class MagickSettings {
86
47
  settings.dispose();
87
48
  }
88
49
  }
50
+ parseDefine(format, name) {
51
+ if (format === magick_format_1.MagickFormat.Unknown)
52
+ return name;
53
+ return `${format}:${name}`;
54
+ }
89
55
  }
90
56
  exports.MagickSettings = MagickSettings;