image-js 1.6.0 → 1.6.1

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * image-js v1.6.0
2
+ * image-js v1.6.1
3
3
  * Image processing and manipulation in JavaScript
4
4
  * https://github.com/image-js/image-js#readme
5
5
  *
@@ -26361,18 +26361,7 @@ ${indent}columns: ${matrix.columns}
26361
26361
  default:
26362
26362
  throw new RangeError(`invalid number of channels: ${png.channels}`);
26363
26363
  }
26364
- let resolution;
26365
- if (png.resolution) {
26366
- resolution = png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26367
- x: png.resolution.x,
26368
- y: png.resolution.y,
26369
- unit: 'meter'
26370
- } : /*If resolution unit is unknown */{
26371
- x: png.resolution.x,
26372
- y: png.resolution.y,
26373
- unit: 'unknown'
26374
- };
26375
- }
26364
+ const resolution = getResolution(png);
26376
26365
  return new Image(png.width, png.height, {
26377
26366
  colorModel,
26378
26367
  bitDepth,
@@ -26404,9 +26393,11 @@ ${indent}columns: ${matrix.columns}
26404
26393
  data[dataIndex++] = paletteChannel;
26405
26394
  }
26406
26395
  }
26396
+ const resolution = getResolution(png);
26407
26397
  return new Image(png.width, png.height, {
26408
26398
  data,
26409
- colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB'
26399
+ colorModel: png.palette[0].length === 4 ? 'RGBA' : 'RGB',
26400
+ resolution
26410
26401
  });
26411
26402
  }
26412
26403
  function decodeBinary(png) {
@@ -26426,6 +26417,26 @@ ${indent}columns: ${matrix.columns}
26426
26417
  }
26427
26418
  return result;
26428
26419
  }
26420
+ /**
26421
+ * Gets image's resolution from its parsed data.
26422
+ * @param png - Parsed .png image.
26423
+ * @returns Object with resolution data if exists.
26424
+ */
26425
+ function getResolution(png) {
26426
+ if (png.resolution) {
26427
+ return png.resolution.unit === 1 ? /*If the resolution unit is meters*/{
26428
+ x: png.resolution.x,
26429
+ y: png.resolution.y,
26430
+ unit: 'meter'
26431
+ } : /*If resolution unit is unknown */{
26432
+ x: png.resolution.x,
26433
+ y: png.resolution.y,
26434
+ unit: 'unknown'
26435
+ };
26436
+ } else {
26437
+ return undefined;
26438
+ }
26439
+ }
26429
26440
 
26430
26441
  /**
26431
26442
  * Decode a TIFF. See the tiff module.