@eris/image
Advanced tools
Comparing version 0.3.1-alpha.8 to 0.3.1-alpha.9
@@ -8,3 +8,3 @@ import * as sharp from 'sharp'; | ||
private readonly _metadata; | ||
constructor(image: sharp.SharpInstance, metadata?: object); | ||
constructor(image: sharp.Sharp, metadata?: object); | ||
private _applyFormat; | ||
@@ -11,0 +11,0 @@ private _applyResize; |
@@ -108,18 +108,18 @@ "use strict"; | ||
} | ||
image = image.resize(width, height); | ||
let sharpFit; | ||
switch (fit) { | ||
case types_1.ImageResizeFit.Contain: | ||
image = image.max(); | ||
sharpFit = 'inside'; | ||
break; | ||
case types_1.ImageResizeFit.Cover: | ||
image = image.min(); | ||
sharpFit = 'outside'; | ||
break; | ||
case types_1.ImageResizeFit.Exact: | ||
image = image.ignoreAspectRatio(); | ||
sharpFit = 'fill'; | ||
break; | ||
case types_1.ImageResizeFit.Crop: | ||
default: | ||
image = image.crop(sharp.gravity.center); | ||
sharpFit = 'cover'; | ||
} | ||
return image; | ||
return image.resize(width, height, { fit: sharpFit }); | ||
}); | ||
@@ -126,0 +126,0 @@ } |
@@ -18,3 +18,3 @@ import * as sharp from 'sharp' | ||
class SharpImage { | ||
public static from(bufferOrImageData: BufferLike | IAnnotatedImageData): sharp.SharpInstance { | ||
public static from(bufferOrImageData: BufferLike | IAnnotatedImageData): sharp.Sharp { | ||
if (ImageData.probablyIs(bufferOrImageData)) { | ||
@@ -39,3 +39,3 @@ let imageData = ImageData.normalize(bufferOrImageData) | ||
public static toMetadata(image: sharp.SharpInstance): Promise<IMetadata> { | ||
public static toMetadata(image: sharp.Sharp): Promise<IMetadata> { | ||
return image.metadata().then(metadata => { | ||
@@ -57,3 +57,3 @@ let {width = 0, height = 0} = metadata | ||
public static async toImageData(image: sharp.SharpInstance): Promise<IAnnotatedImageData> { | ||
public static async toImageData(image: sharp.Sharp): Promise<IAnnotatedImageData> { | ||
const rawData = await (image.clone().raw().toBuffer as any)({resolveWithObject: true}) | ||
@@ -74,6 +74,6 @@ const {width, height, size} = rawData.info | ||
export class NodeImage extends Image { | ||
private readonly _image: sharp.SharpInstance | ||
private readonly _image: sharp.Sharp | ||
private readonly _metadata: object | undefined | ||
public constructor(image: sharp.SharpInstance, metadata?: object) { | ||
public constructor(image: sharp.Sharp, metadata?: object) { | ||
super() | ||
@@ -84,3 +84,3 @@ this._image = image | ||
private _applyFormat(image: sharp.SharpInstance): sharp.SharpInstance { | ||
private _applyFormat(image: sharp.Sharp): sharp.Sharp { | ||
const {format = DEFAULT_FORMAT} = this._output | ||
@@ -98,3 +98,3 @@ if (format.type === ImageFormat.JPEG) { | ||
private async _applyResize(image: sharp.SharpInstance): Promise<sharp.SharpInstance> { | ||
private async _applyResize(image: sharp.Sharp): Promise<sharp.Sharp> { | ||
if (!this._output.resize) { | ||
@@ -120,22 +120,22 @@ return image | ||
image = image.resize(width, height) | ||
let sharpFit: sharp.ResizeOptions['fit'] | ||
switch (fit) { | ||
case ImageResizeFit.Contain: | ||
image = image.max() | ||
sharpFit = 'inside' | ||
break | ||
case ImageResizeFit.Cover: | ||
image = image.min() | ||
sharpFit = 'outside' | ||
break | ||
case ImageResizeFit.Exact: | ||
image = image.ignoreAspectRatio() | ||
sharpFit = 'fill' | ||
break | ||
case ImageResizeFit.Crop: | ||
default: | ||
image = image.crop(sharp.gravity.center) | ||
sharpFit = 'cover' | ||
} | ||
return image | ||
return image.resize(width, height, {fit: sharpFit}) | ||
} | ||
private _applyGreyscale(image: sharp.SharpInstance): sharp.SharpInstance { | ||
private _applyGreyscale(image: sharp.Sharp): sharp.Sharp { | ||
if (!this._output.greyscale || this._output.edges) { | ||
@@ -148,5 +148,3 @@ return image | ||
private async _applyImageDataTransforms( | ||
image: sharp.SharpInstance, | ||
): Promise<sharp.SharpInstance> { | ||
private async _applyImageDataTransforms(image: sharp.Sharp): Promise<sharp.Sharp> { | ||
if ( | ||
@@ -174,3 +172,3 @@ !this._output.effects && | ||
private async _applyAll(imagePromise: sharp.SharpInstance): Promise<sharp.SharpInstance> { | ||
private async _applyAll(imagePromise: sharp.Sharp): Promise<sharp.Sharp> { | ||
let image = await imagePromise | ||
@@ -177,0 +175,0 @@ |
{ | ||
"name": "@eris/image", | ||
"version": "0.3.1-alpha.8", | ||
"version": "0.3.1-alpha.9", | ||
"description": "Collection of image manipulation libraries for node and the browser.", | ||
@@ -38,3 +38,4 @@ "main": "./dist/node-index.js", | ||
"dependencies": { | ||
"@eris/exif": "0.3.1-alpha.8", | ||
"@eris/exif": "0.3.1-alpha.9", | ||
"@types/sharp": "^0.22.0", | ||
"buffer": "^5.2.0", | ||
@@ -44,3 +45,3 @@ "file-type": "^7.0.1", | ||
"pngjs": "^3.3.0", | ||
"sharp": "^0.18.4" | ||
"sharp": "^0.22.0" | ||
}, | ||
@@ -50,3 +51,2 @@ "devDependencies": { | ||
"@types/node": "^7.0.18", | ||
"@types/sharp": "^0.17.1", | ||
"babili": "^0.1.2", | ||
@@ -73,3 +73,3 @@ "chai": "^3.5.0", | ||
}, | ||
"gitHead": "95077f78063a814ec94b18b93e8c0c658c5b8ee9" | ||
"gitHead": "e2d64d60a7d47afc31f318140b91c8f33243a179" | ||
} |
Sorry, the diff of this file is not supported yet
22
1792480
7
15369
+ Added@types/sharp@^0.22.0
+ Added@eris/exif@0.3.1-alpha.9(transitive)
+ Added@types/node@22.13.1(transitive)
+ Added@types/sharp@0.22.3(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedaproba@1.2.0(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedcode-point-at@1.1.0(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddeep-extend@0.6.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@1.0.3(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexpand-template@2.0.3(transitive)
+ Addedfs-constants@1.0.0(transitive)
+ Addedfs-copy-file-sync@1.1.1(transitive)
+ Addedfs-minipass@1.2.7(transitive)
+ Addedgauge@2.7.4(transitive)
+ Addedgithub-from-package@0.0.0(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addednapi-build-utils@1.0.2(transitive)
+ Addednode-abi@2.30.1(transitive)
+ Addednoop-logger@0.1.1(transitive)
+ Addednpmlog@4.1.2(transitive)
+ Addednumber-is-nan@1.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedprebuild-install@5.3.6(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedrc@1.2.8(transitive)
+ Addedreadable-stream@2.3.83.6.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsharp@0.22.1(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedstring-width@1.0.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedstrip-ansi@3.0.1(transitive)
+ Addedstrip-json-comments@2.0.1(transitive)
+ Addedtar@4.4.19(transitive)
+ Addedtar-fs@2.1.2(transitive)
+ Addedtar-stream@2.2.0(transitive)
+ Addedundici-types@6.20.0(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwhich-pm-runs@1.1.0(transitive)
+ Addedwide-align@1.1.5(transitive)
- Removed@eris/exif@0.3.1-alpha.8(transitive)
- Removedcaw@2.0.1(transitive)
- Removedcolor@2.0.1(transitive)
- Removedconfig-chain@1.1.13(transitive)
- Removeddecompress-response@3.3.0(transitive)
- Removeddetect-libc@0.2.0(transitive)
- Removedget-proxy@2.1.0(transitive)
- Removedhas-symbol-support-x@1.4.2(transitive)
- Removedhas-to-string-tag-x@1.4.1(transitive)
- Removedis-object@1.0.2(transitive)
- Removedisurl@1.0.0(transitive)
- Removedmimic-response@1.0.1(transitive)
- Removednpm-conf@1.1.3(transitive)
- Removedpify@3.0.0(transitive)
- Removedproto-list@1.2.4(transitive)
- Removedsharp@0.18.4(transitive)
- Removedsimple-get@2.8.2(transitive)
- Removedtar@3.2.3(transitive)
- Removedurl-to-options@1.0.1(transitive)
Updated@eris/exif@0.3.1-alpha.9
Updatedsharp@^0.22.0