@imagemagick/magick-wasm 0.0.6 → 0.0.10

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/README.md CHANGED
@@ -1,17 +1,17 @@
1
- ## The WebAssembly library for ImageMagick: Magick.WASM
1
+ ## The WebAssembly library for ImageMagick: magick-wasm
2
2
 
3
- [![GitHub license](https://img.shields.io/badge/license-Apache%202-green.svg)](https://raw.githubusercontent.com/dlemstra/Magick.WASM/master/license.txt)
3
+ [![GitHub license](https://img.shields.io/badge/license-Apache%202-green.svg)](https://raw.githubusercontent.com/dlemstra/magick-wasm/main/license.txt)
4
4
  [![Twitter URL](https://img.shields.io/badge/twitter-follow-1da1f2.svg)](https://twitter.com/MagickNET)
5
5
  [![Donate](https://img.shields.io/badge/%24-donate-ff00ff.svg)](https://github.com/sponsors/dlemstra)
6
6
 
7
7
  ImageMagick is a powerful image manipulation library that supports over [100 major file formats](https://www.imagemagick.org/script/formats.php) (not including sub-formats).
8
- With Magick.WASM you can use ImageMagick in your web application without doing a callback to an api.
8
+ With magick-wasm you can use ImageMagick in your web application without doing a callback to an api.
9
9
 
10
10
  ## Documentation
11
11
 
12
- For examples on how to use Magick.WASM view the [demo.ts](https://github.com/dlemstra/Magick.WASM/blob/master/demo/demo.ts).
12
+ For examples on how to use magick-wasm view the [demo.ts](https://github.com/dlemstra/magick-wasm/blob/main/demo/demo.ts).
13
13
  For more information about ImageMagick go to: [http://www.imagemagick.org/](http://www.imagemagick.org/).
14
14
 
15
15
  ## Release notes
16
16
 
17
- The release notes can be found on [GitHub](https://github.com/dlemstra/Magick.WASM/releases/tag/0.0.6).
17
+ The release notes can be found on [GitHub](https://github.com/dlemstra/magick-wasm/releases/tag/0.0.10).
@@ -0,0 +1,6 @@
1
+ export declare enum AutoThresholdMethod {
2
+ Undefined = 0,
3
+ Kapur = 1,
4
+ OTSU = 2,
5
+ Triangle = 3
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AutoThresholdMethod = void 0;
4
+ var AutoThresholdMethod;
5
+ (function (AutoThresholdMethod) {
6
+ AutoThresholdMethod[AutoThresholdMethod["Undefined"] = 0] = "Undefined";
7
+ AutoThresholdMethod[AutoThresholdMethod["Kapur"] = 1] = "Kapur";
8
+ AutoThresholdMethod[AutoThresholdMethod["OTSU"] = 2] = "OTSU";
9
+ AutoThresholdMethod[AutoThresholdMethod["Triangle"] = 3] = "Triangle";
10
+ })(AutoThresholdMethod = exports.AutoThresholdMethod || (exports.AutoThresholdMethod = {}));
@@ -0,0 +1,34 @@
1
+ export declare enum FilterType {
2
+ Undefined = 0,
3
+ Point = 1,
4
+ Box = 2,
5
+ Triangle = 3,
6
+ Hermite = 4,
7
+ Hann = 5,
8
+ Hamming = 6,
9
+ Blackman = 7,
10
+ Gaussian = 8,
11
+ Quadratic = 9,
12
+ Cubic = 10,
13
+ Catrom = 11,
14
+ Mitchell = 12,
15
+ Jinc = 13,
16
+ Sinc = 14,
17
+ SincFast = 15,
18
+ Kaiser = 16,
19
+ Welch = 17,
20
+ Parzen = 18,
21
+ Bohman = 19,
22
+ Bartlett = 20,
23
+ Lagrange = 21,
24
+ Lanczos = 22,
25
+ LanczosSharp = 23,
26
+ Lanczos2 = 24,
27
+ Lanczos2Sharp = 25,
28
+ Robidoux = 26,
29
+ RobidouxSharp = 27,
30
+ Cosine = 28,
31
+ Spline = 29,
32
+ LanczosRadius = 30,
33
+ CubicSpline = 31
34
+ }
package/filter-type.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterType = void 0;
4
+ var FilterType;
5
+ (function (FilterType) {
6
+ FilterType[FilterType["Undefined"] = 0] = "Undefined";
7
+ FilterType[FilterType["Point"] = 1] = "Point";
8
+ FilterType[FilterType["Box"] = 2] = "Box";
9
+ FilterType[FilterType["Triangle"] = 3] = "Triangle";
10
+ FilterType[FilterType["Hermite"] = 4] = "Hermite";
11
+ FilterType[FilterType["Hann"] = 5] = "Hann";
12
+ FilterType[FilterType["Hamming"] = 6] = "Hamming";
13
+ FilterType[FilterType["Blackman"] = 7] = "Blackman";
14
+ FilterType[FilterType["Gaussian"] = 8] = "Gaussian";
15
+ FilterType[FilterType["Quadratic"] = 9] = "Quadratic";
16
+ FilterType[FilterType["Cubic"] = 10] = "Cubic";
17
+ FilterType[FilterType["Catrom"] = 11] = "Catrom";
18
+ FilterType[FilterType["Mitchell"] = 12] = "Mitchell";
19
+ FilterType[FilterType["Jinc"] = 13] = "Jinc";
20
+ FilterType[FilterType["Sinc"] = 14] = "Sinc";
21
+ FilterType[FilterType["SincFast"] = 15] = "SincFast";
22
+ FilterType[FilterType["Kaiser"] = 16] = "Kaiser";
23
+ FilterType[FilterType["Welch"] = 17] = "Welch";
24
+ FilterType[FilterType["Parzen"] = 18] = "Parzen";
25
+ FilterType[FilterType["Bohman"] = 19] = "Bohman";
26
+ FilterType[FilterType["Bartlett"] = 20] = "Bartlett";
27
+ FilterType[FilterType["Lagrange"] = 21] = "Lagrange";
28
+ FilterType[FilterType["Lanczos"] = 22] = "Lanczos";
29
+ FilterType[FilterType["LanczosSharp"] = 23] = "LanczosSharp";
30
+ FilterType[FilterType["Lanczos2"] = 24] = "Lanczos2";
31
+ FilterType[FilterType["Lanczos2Sharp"] = 25] = "Lanczos2Sharp";
32
+ FilterType[FilterType["Robidoux"] = 26] = "Robidoux";
33
+ FilterType[FilterType["RobidouxSharp"] = 27] = "RobidouxSharp";
34
+ FilterType[FilterType["Cosine"] = 28] = "Cosine";
35
+ FilterType[FilterType["Spline"] = 29] = "Spline";
36
+ FilterType[FilterType["LanczosRadius"] = 30] = "LanczosRadius";
37
+ FilterType[FilterType["CubicSpline"] = 31] = "CubicSpline";
38
+ })(FilterType = exports.FilterType || (exports.FilterType = {}));
package/gravity.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Gravity = void 0;
3
+ exports._getEdges = exports.Gravity = void 0;
4
4
  var Gravity;
5
5
  (function (Gravity) {
6
6
  Gravity[Gravity["Undefined"] = 0] = "Undefined";
@@ -15,3 +15,37 @@ var Gravity;
15
15
  Gravity[Gravity["South"] = 8] = "South";
16
16
  Gravity[Gravity["Southeast"] = 9] = "Southeast";
17
17
  })(Gravity = exports.Gravity || (exports.Gravity = {}));
18
+ function* _getEdges(gravities) {
19
+ for (const gravity of gravities) {
20
+ switch (gravity) {
21
+ case Gravity.North:
22
+ yield 'north';
23
+ break;
24
+ case Gravity.Northeast:
25
+ yield 'north';
26
+ yield 'east';
27
+ break;
28
+ case Gravity.Northwest:
29
+ yield 'north';
30
+ yield 'west';
31
+ break;
32
+ case Gravity.East:
33
+ yield 'east';
34
+ break;
35
+ case Gravity.West:
36
+ yield 'west';
37
+ break;
38
+ case Gravity.South:
39
+ yield 'south';
40
+ break;
41
+ case Gravity.Southeast:
42
+ yield 'south';
43
+ yield 'east';
44
+ break;
45
+ case Gravity.Southwest:
46
+ yield 'south';
47
+ yield 'west';
48
+ }
49
+ }
50
+ }
51
+ exports._getEdges = _getEdges;
package/image-magick.js CHANGED
@@ -17,14 +17,19 @@ const magick_js_1 = __importDefault(require("./wasm/magick.js"));
17
17
  const magick_image_1 = require("./magick-image");
18
18
  const magick_image_collection_1 = require("./magick-image-collection");
19
19
  const magick_color_1 = require("./magick-color");
20
+ const magick_error_1 = require("./magick-error");
20
21
  const magick_read_settings_1 = require("./settings/magick-read-settings");
21
22
  const string_1 = require("./internal/native/string");
22
23
  class ImageMagick {
23
24
  constructor() {
24
25
  this.loader = new Promise(resolve => {
25
- magick_js_1.default().then(api => {
26
- string_1._withNativeString(api, 'MAGICK_CONFIGURE_PATH', name => {
27
- string_1._withNativeString(api, '/xml', value => {
26
+ if (this.api !== undefined) {
27
+ resolve();
28
+ return;
29
+ }
30
+ (0, magick_js_1.default)().then(api => {
31
+ (0, string_1._withNativeString)(api, 'MAGICK_CONFIGURE_PATH', name => {
32
+ (0, string_1._withNativeString)(api, '/xml', value => {
28
33
  api._Environment_SetEnv(name, value);
29
34
  this.api = api;
30
35
  });
@@ -38,7 +43,7 @@ class ImageMagick {
38
43
  }
39
44
  static get _api() {
40
45
  if (instance.api === undefined)
41
- throw new Error('`await initializeImageMagick` should be called to initialize the library');
46
+ throw new magick_error_1.MagickError('`await initializeImageMagick` should be called to initialize the library');
42
47
  return instance.api;
43
48
  }
44
49
  static set _api(value) {
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Exception = void 0;
4
4
  const image_magick_1 = require("../../image-magick");
5
- const exception_severity_1 = require("./exception-severity");
5
+ const magick_error_1 = require("../../magick-error");
6
+ const magick_error_severity_1 = require("../../magick-error-severity");
6
7
  const pointer_1 = require("../pointer/pointer");
7
8
  const string_1 = require("../native/string");
8
9
  class Exception {
@@ -11,7 +12,7 @@ class Exception {
11
12
  }
12
13
  get ptr() { return this.pointer.ptr; }
13
14
  check(success, error) {
14
- if (Exception.isRaised(this.pointer) && Exception.isErrorSeverity(this.pointer))
15
+ if (this.isError())
15
16
  return error();
16
17
  return success();
17
18
  }
@@ -30,28 +31,34 @@ class Exception {
30
31
  static checkException(exception, result) {
31
32
  if (!Exception.isRaised(exception))
32
33
  return result;
33
- if (Exception.isErrorSeverity(exception))
34
- Exception.throw(exception);
34
+ const severity = Exception.getErrorSeverity(exception);
35
+ if (severity >= magick_error_severity_1.MagickErrorSeverity.Error)
36
+ Exception.throw(exception, severity);
35
37
  else
36
38
  Exception.dispose(exception);
37
39
  return result;
38
40
  }
39
- static isErrorSeverity(exception) {
40
- const severity = image_magick_1.ImageMagick._api._MagickExceptionHelper_Severity(exception.value);
41
- return severity >= exception_severity_1.ExceptionSeverity.Error;
41
+ isError() {
42
+ if (!Exception.isRaised(this.pointer))
43
+ return false;
44
+ const severity = Exception.getErrorSeverity(this.pointer);
45
+ return severity >= magick_error_severity_1.MagickErrorSeverity.Error;
46
+ }
47
+ static getErrorSeverity(exception) {
48
+ return image_magick_1.ImageMagick._api._MagickExceptionHelper_Severity(exception.value);
42
49
  }
43
50
  static isRaised(exception) {
44
51
  return exception.value !== 0;
45
52
  }
46
- static throw(exception) {
53
+ static throw(exception, severity) {
47
54
  const errorMessage = Exception.getMessage(exception);
48
55
  Exception.dispose(exception);
49
- throw new Error(errorMessage);
56
+ throw new magick_error_1.MagickError(errorMessage, severity);
50
57
  }
51
58
  static getMessage(exception) {
52
59
  const message = image_magick_1.ImageMagick._api._MagickExceptionHelper_Message(exception.value);
53
60
  const description = image_magick_1.ImageMagick._api._MagickExceptionHelper_Description(exception.value);
54
- let errorMessage = string_1._createString(message, 'Unknown error');
61
+ let errorMessage = (0, string_1._createString)(message, 'Unknown error');
55
62
  if (description !== 0) {
56
63
  errorMessage += `(${image_magick_1.ImageMagick._api.UTF8ToString(description)})`;
57
64
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NativeInstance = void 0;
4
+ const magick_error_1 = require("../magick-error");
4
5
  class NativeInstance {
5
6
  constructor(instance, disposeMethod) {
6
7
  this.instance = instance;
@@ -11,7 +12,7 @@ class NativeInstance {
11
12
  return this.instance;
12
13
  if (this.instance === -1)
13
14
  this._instanceNotInitialized();
14
- throw new Error('instance is disposed');
15
+ throw new magick_error_1.MagickError('instance is disposed');
15
16
  }
16
17
  set _instance(instance) {
17
18
  this.disposeInstance(this.instance);
@@ -29,7 +30,7 @@ class NativeInstance {
29
30
  });
30
31
  }
31
32
  _instanceNotInitialized() {
32
- throw new Error('instance is not initialized');
33
+ throw new magick_error_1.MagickError('instance is not initialized');
33
34
  }
34
35
  disposeInstance(instance) {
35
36
  if (instance > 0)
package/magick-color.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MagickColor = void 0;
4
4
  const image_magick_1 = require("./image-magick");
5
+ const magick_error_1 = require("./magick-error");
5
6
  const quantum_1 = require("./quantum");
6
7
  const string_1 = require("./internal/native/string");
7
8
  class MagickColor {
@@ -18,9 +19,9 @@ class MagickColor {
18
19
  let instance = 0;
19
20
  try {
20
21
  instance = image_magick_1.ImageMagick._api._MagickColor_Create();
21
- string_1._withString(colorOrRed, colorPtr => {
22
+ (0, string_1._withString)(colorOrRed, colorPtr => {
22
23
  if (image_magick_1.ImageMagick._api._MagickColor_Initialize(instance, colorPtr) === 0)
23
- throw new Error('invalid color specified');
24
+ throw new magick_error_1.MagickError('invalid color specified');
24
25
  this.initialize(instance);
25
26
  });
26
27
  }
@@ -0,0 +1,25 @@
1
+ export declare enum MagickErrorSeverity {
2
+ Error = 400,
3
+ ResourceLimitError = 400,
4
+ TypeError = 405,
5
+ OptionError = 410,
6
+ DelegateError = 415,
7
+ MissingDelegateError = 420,
8
+ CorruptImageError = 425,
9
+ FileOpenError = 430,
10
+ BlobError = 435,
11
+ StreamError = 440,
12
+ CacheError = 445,
13
+ CoderError = 450,
14
+ FilterError = 452,
15
+ ModuleError = 455,
16
+ DrawError = 460,
17
+ ImageError = 465,
18
+ WandError = 470,
19
+ RandomError = 475,
20
+ XServerError = 480,
21
+ MonitorError = 485,
22
+ RegistryError = 490,
23
+ ConfigureError = 495,
24
+ PolicyError = 499
25
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagickErrorSeverity = void 0;
4
+ var MagickErrorSeverity;
5
+ (function (MagickErrorSeverity) {
6
+ MagickErrorSeverity[MagickErrorSeverity["Error"] = 400] = "Error";
7
+ MagickErrorSeverity[MagickErrorSeverity["ResourceLimitError"] = 400] = "ResourceLimitError";
8
+ MagickErrorSeverity[MagickErrorSeverity["TypeError"] = 405] = "TypeError";
9
+ MagickErrorSeverity[MagickErrorSeverity["OptionError"] = 410] = "OptionError";
10
+ MagickErrorSeverity[MagickErrorSeverity["DelegateError"] = 415] = "DelegateError";
11
+ MagickErrorSeverity[MagickErrorSeverity["MissingDelegateError"] = 420] = "MissingDelegateError";
12
+ MagickErrorSeverity[MagickErrorSeverity["CorruptImageError"] = 425] = "CorruptImageError";
13
+ MagickErrorSeverity[MagickErrorSeverity["FileOpenError"] = 430] = "FileOpenError";
14
+ MagickErrorSeverity[MagickErrorSeverity["BlobError"] = 435] = "BlobError";
15
+ MagickErrorSeverity[MagickErrorSeverity["StreamError"] = 440] = "StreamError";
16
+ MagickErrorSeverity[MagickErrorSeverity["CacheError"] = 445] = "CacheError";
17
+ MagickErrorSeverity[MagickErrorSeverity["CoderError"] = 450] = "CoderError";
18
+ MagickErrorSeverity[MagickErrorSeverity["FilterError"] = 452] = "FilterError";
19
+ MagickErrorSeverity[MagickErrorSeverity["ModuleError"] = 455] = "ModuleError";
20
+ MagickErrorSeverity[MagickErrorSeverity["DrawError"] = 460] = "DrawError";
21
+ MagickErrorSeverity[MagickErrorSeverity["ImageError"] = 465] = "ImageError";
22
+ MagickErrorSeverity[MagickErrorSeverity["WandError"] = 470] = "WandError";
23
+ MagickErrorSeverity[MagickErrorSeverity["RandomError"] = 475] = "RandomError";
24
+ MagickErrorSeverity[MagickErrorSeverity["XServerError"] = 480] = "XServerError";
25
+ MagickErrorSeverity[MagickErrorSeverity["MonitorError"] = 485] = "MonitorError";
26
+ MagickErrorSeverity[MagickErrorSeverity["RegistryError"] = 490] = "RegistryError";
27
+ MagickErrorSeverity[MagickErrorSeverity["ConfigureError"] = 495] = "ConfigureError";
28
+ MagickErrorSeverity[MagickErrorSeverity["PolicyError"] = 499] = "PolicyError";
29
+ })(MagickErrorSeverity = exports.MagickErrorSeverity || (exports.MagickErrorSeverity = {}));
@@ -0,0 +1,6 @@
1
+ import { MagickErrorSeverity } from "./magick-error-severity";
2
+ export declare class MagickError extends Error {
3
+ private readonly _severity;
4
+ constructor(message: string, severity?: MagickErrorSeverity);
5
+ get severity(): MagickErrorSeverity;
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagickError = void 0;
4
+ const magick_error_severity_1 = require("./magick-error-severity");
5
+ class MagickError extends Error {
6
+ constructor(message, severity = magick_error_severity_1.MagickErrorSeverity.Error) {
7
+ super(message);
8
+ this._severity = severity;
9
+ }
10
+ get severity() { return this._severity; }
11
+ }
12
+ exports.MagickError = MagickError;
@@ -27,9 +27,9 @@ class MagickFormatInfo {
27
27
  const values = Object.values(magick_format_1.MagickFormat);
28
28
  for (let i = 0; i < count; i++) {
29
29
  const info = image_magick_1.ImageMagick._api._MagickFormatInfo_GetInfo(list, i, exception);
30
- const formatName = string_1._createString(image_magick_1.ImageMagick._api._MagickFormatInfo_Format_Get(info));
30
+ const formatName = (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickFormatInfo_Format_Get(info));
31
31
  const format = MagickFormatInfo.convertFormat(formatName, values);
32
- const description = string_1._createString(image_magick_1.ImageMagick._api._MagickFormatInfo_Description_Get(info), '');
32
+ const description = (0, string_1._createString)(image_magick_1.ImageMagick._api._MagickFormatInfo_Description_Get(info), '');
33
33
  const isReadable = image_magick_1.ImageMagick._api._MagickFormatInfo_IsReadable_Get(info) == 1;
34
34
  const isWritable = image_magick_1.ImageMagick._api._MagickFormatInfo_IsWritable_Get(info) == 1;
35
35
  result[i] = new MagickFormatInfo(format, description, isReadable, isWritable);
@@ -59,6 +59,7 @@ export declare enum MagickFormat {
59
59
  Ept2 = "EPT2",
60
60
  Ept3 = "EPT3",
61
61
  Erf = "ERF",
62
+ Exr = "EXR",
62
63
  Farbfeld = "FARBFELD",
63
64
  Fax = "FAX",
64
65
  FF = "FF",
@@ -68,6 +69,7 @@ export declare enum MagickFormat {
68
69
  Flv = "FLV",
69
70
  Fractal = "FRACTAL",
70
71
  Ftp = "FTP",
72
+ Ftxt = "FTXT",
71
73
  Fts = "FTS",
72
74
  G = "G",
73
75
  G3 = "G3",
@@ -189,6 +191,7 @@ export declare enum MagickFormat {
189
191
  Psd = "PSD",
190
192
  Ptif = "PTIF",
191
193
  Pwp = "PWP",
194
+ Qoi = "QOI",
192
195
  R = "R",
193
196
  RadialGradient = "RADIAL-GRADIENT",
194
197
  Raf = "RAF",
@@ -215,6 +218,7 @@ export declare enum MagickFormat {
215
218
  Sr2 = "SR2",
216
219
  Srf = "SRF",
217
220
  Stegano = "STEGANO",
221
+ StrImg = "STRIMG",
218
222
  Sun = "SUN",
219
223
  Svg = "SVG",
220
224
  Svgz = "SVGZ",
package/magick-format.js CHANGED
@@ -63,6 +63,7 @@ var MagickFormat;
63
63
  MagickFormat["Ept2"] = "EPT2";
64
64
  MagickFormat["Ept3"] = "EPT3";
65
65
  MagickFormat["Erf"] = "ERF";
66
+ MagickFormat["Exr"] = "EXR";
66
67
  MagickFormat["Farbfeld"] = "FARBFELD";
67
68
  MagickFormat["Fax"] = "FAX";
68
69
  MagickFormat["FF"] = "FF";
@@ -72,6 +73,7 @@ var MagickFormat;
72
73
  MagickFormat["Flv"] = "FLV";
73
74
  MagickFormat["Fractal"] = "FRACTAL";
74
75
  MagickFormat["Ftp"] = "FTP";
76
+ MagickFormat["Ftxt"] = "FTXT";
75
77
  MagickFormat["Fts"] = "FTS";
76
78
  MagickFormat["G"] = "G";
77
79
  MagickFormat["G3"] = "G3";
@@ -193,6 +195,7 @@ var MagickFormat;
193
195
  MagickFormat["Psd"] = "PSD";
194
196
  MagickFormat["Ptif"] = "PTIF";
195
197
  MagickFormat["Pwp"] = "PWP";
198
+ MagickFormat["Qoi"] = "QOI";
196
199
  MagickFormat["R"] = "R";
197
200
  MagickFormat["RadialGradient"] = "RADIAL-GRADIENT";
198
201
  MagickFormat["Raf"] = "RAF";
@@ -219,6 +222,7 @@ var MagickFormat;
219
222
  MagickFormat["Sr2"] = "SR2";
220
223
  MagickFormat["Srf"] = "SRF";
221
224
  MagickFormat["Stegano"] = "STEGANO";
225
+ MagickFormat["StrImg"] = "STRIMG";
222
226
  MagickFormat["Sun"] = "SUN";
223
227
  MagickFormat["Svg"] = "SVG";
224
228
  MagickFormat["Svgz"] = "SVGZ";
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MagickGeometry = void 0;
4
4
  const image_magick_1 = require("./image-magick");
5
5
  const geometry_flags_1 = require("./internal/geometry-flags");
6
+ const magick_error_1 = require("./magick-error");
6
7
  const string_1 = require("./internal/native/string");
7
8
  class MagickGeometry {
8
9
  constructor(widthOrValueOrX, heightOrY, width, height) {
@@ -31,17 +32,17 @@ class MagickGeometry {
31
32
  this._y = 0;
32
33
  }
33
34
  if (this._width < 0)
34
- throw new Error('negative width is not allowed');
35
+ throw new magick_error_1.MagickError('negative width is not allowed');
35
36
  if (this._height < 0)
36
- throw new Error('negative height is not allowed');
37
+ throw new magick_error_1.MagickError('negative height is not allowed');
37
38
  }
38
39
  else {
39
40
  const instance = image_magick_1.ImageMagick._api._MagickGeometry_Create();
40
41
  try {
41
- string_1._withString(widthOrValueOrX, valuePtr => {
42
+ (0, string_1._withString)(widthOrValueOrX, valuePtr => {
42
43
  const flags = image_magick_1.ImageMagick._api._MagickGeometry_Initialize(instance, valuePtr);
43
44
  if (flags === geometry_flags_1.GeometryFlags.NoValue)
44
- throw new Error('invalid geometry specified');
45
+ throw new magick_error_1.MagickError('invalid geometry specified');
45
46
  if (this.hasFlag(flags, geometry_flags_1.GeometryFlags.AspectRatio)) {
46
47
  this.initializeFromAspectRation(instance, widthOrValueOrX);
47
48
  }
@@ -108,6 +109,35 @@ class MagickGeometry {
108
109
  result += '@';
109
110
  return result;
110
111
  }
112
+ static fromRectangle(rectangle) {
113
+ if (rectangle === 0)
114
+ throw new magick_error_1.MagickError('unable to allocate memory');
115
+ try {
116
+ const width = image_magick_1.ImageMagick._api._MagickRectangle_Width_Get(rectangle);
117
+ const height = image_magick_1.ImageMagick._api._MagickRectangle_Height_Get(rectangle);
118
+ const x = image_magick_1.ImageMagick._api._MagickRectangle_X_Get(rectangle);
119
+ const y = image_magick_1.ImageMagick._api._MagickRectangle_Y_Get(rectangle);
120
+ return new MagickGeometry(x, y, width, height);
121
+ }
122
+ finally {
123
+ image_magick_1.ImageMagick._api._MagickRectangle_Dispose(rectangle);
124
+ }
125
+ }
126
+ toRectangle(func) {
127
+ const rectangle = image_magick_1.ImageMagick._api._MagickRectangle_Create();
128
+ if (rectangle === 0)
129
+ throw new magick_error_1.MagickError('unable to allocate memory');
130
+ try {
131
+ image_magick_1.ImageMagick._api._MagickRectangle_Width_Set(rectangle, this._width);
132
+ image_magick_1.ImageMagick._api._MagickRectangle_Height_Set(rectangle, this._height);
133
+ image_magick_1.ImageMagick._api._MagickRectangle_X_Set(rectangle, this._x);
134
+ image_magick_1.ImageMagick._api._MagickRectangle_Y_Set(rectangle, this._y);
135
+ func(rectangle);
136
+ }
137
+ finally {
138
+ image_magick_1.ImageMagick._api._MagickRectangle_Dispose(rectangle);
139
+ }
140
+ }
111
141
  initialize(instance, flags) {
112
142
  this._width = image_magick_1.ImageMagick._api._MagickGeometry_Width_Get(instance);
113
143
  this._height = image_magick_1.ImageMagick._api._MagickGeometry_Height_Get(instance);