From e3549ba28cd1fc51827e3818e651363af99648da Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 28 Jan 2019 22:11:18 +0000 Subject: [PATCH] Remove functions previously deprecated in v0.21.0 background, crop, embed, ignoreAspectRatio, max, min, withoutEnlargement --- docs/changelog.md | 9 + lib/colour.js | 22 -- lib/resize.js | 94 ------ test/unit/deprecated-background.js | 73 ----- test/unit/deprecated-crop.js | 279 ------------------ test/unit/deprecated-embed.js | 440 ----------------------------- test/unit/deprecated-resize.js | 261 ----------------- 7 files changed, 9 insertions(+), 1169 deletions(-) delete mode 100644 test/unit/deprecated-background.js delete mode 100644 test/unit/deprecated-crop.js delete mode 100644 test/unit/deprecated-embed.js delete mode 100644 test/unit/deprecated-resize.js diff --git a/docs/changelog.md b/docs/changelog.md index 4743a866..d1cd5d0d 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,14 @@ # Changelog +### v0.22 - "*uptake*" + +Requires libvips v8.7.4. + +#### v0.22.0 - TBD + +* Remove functions previously deprecated in v0.21.0: + `background`, `crop`, `embed`, `ignoreAspectRatio`, `max`, `min` and `withoutEnlargement`. + ### v0.21 - "*teeth*" Requires libvips v8.7.0. diff --git a/lib/colour.js b/lib/colour.js index cd0f29da..366dbf42 100644 --- a/lib/colour.js +++ b/lib/colour.js @@ -1,7 +1,5 @@ 'use strict'; -const deprecate = require('util').deprecate; - const color = require('color'); const is = require('./is'); @@ -17,24 +15,6 @@ const colourspace = { srgb: 'srgb' }; -/** - * @deprecated - * @private - */ -function background (rgba) { - const colour = color(rgba); - const background = [ - colour.red(), - colour.green(), - colour.blue(), - Math.round(colour.alpha() * 255) - ]; - this.options.resizeBackground = background; - this.options.extendBackground = background; - this.options.flattenBackground = background.slice(0, 3); - return this; -} - /** * Tint the image using the provided chroma while preserving the image luminance. * An alpha channel may be present and will be unchanged by the operation. @@ -136,6 +116,4 @@ module.exports = function (Sharp) { // Class attributes Sharp.colourspace = colourspace; Sharp.colorspace = colourspace; - // Deprecated - Sharp.prototype.background = deprecate(background, 'background(background) is deprecated, use resize({ background }), extend({ background }) or flatten({ background }) instead'); }; diff --git a/lib/resize.js b/lib/resize.js index 9d703f9f..1f282493 100644 --- a/lib/resize.js +++ b/lib/resize.js @@ -1,6 +1,5 @@ 'use strict'; -const deprecate = require('util').deprecate; const is = require('./is'); /** @@ -378,92 +377,6 @@ function trim (threshold) { return this; } -// Deprecated functions - -/** - * @deprecated - * @private - */ -function crop (crop) { - this.options.canvas = 'crop'; - if (!is.defined(crop)) { - // Default - this.options.position = gravity.center; - } else if (is.integer(crop) && is.inRange(crop, 0, 8)) { - // Gravity (numeric) - this.options.position = crop; - } else if (is.string(crop) && is.integer(gravity[crop])) { - // Gravity (string) - this.options.position = gravity[crop]; - } else if (is.integer(crop) && crop >= strategy.entropy) { - // Strategy - this.options.position = crop; - } else if (is.string(crop) && is.integer(strategy[crop])) { - // Strategy (string) - this.options.position = strategy[crop]; - } else { - throw is.invalidParameterError('crop', 'valid crop id/name/strategy', crop); - } - return this; -} - -/** - * @deprecated - * @private - */ -function embed (embed) { - this.options.canvas = 'embed'; - if (!is.defined(embed)) { - // Default - this.options.position = gravity.center; - } else if (is.integer(embed) && is.inRange(embed, 0, 8)) { - // Gravity (numeric) - this.options.position = embed; - } else if (is.string(embed) && is.integer(gravity[embed])) { - // Gravity (string) - this.options.position = gravity[embed]; - } else { - throw is.invalidParameterError('embed', 'valid embed id/name', embed); - } - return this; -} - -/** - * @deprecated - * @private - */ -function max () { - this.options.canvas = 'max'; - return this; -} - -/** - * @deprecated - * @private - */ -function min () { - this.options.canvas = 'min'; - return this; -} - -/** - * @deprecated - * @private - */ -function ignoreAspectRatio () { - this.options.canvas = 'ignore_aspect'; - return this; -} - -/** - * @deprecated - * @private -*/ -function withoutEnlargement (withoutEnlargement) { - this.options.withoutEnlargement = is.bool(withoutEnlargement) ? withoutEnlargement : true; - return this; -} - /** * Decorate the Sharp prototype with resize-related functions. * @private @@ -481,11 +394,4 @@ module.exports = function (Sharp) { Sharp.kernel = kernel; Sharp.fit = fit; Sharp.position = position; - // Deprecated functions, to be removed in v0.22.0 - Sharp.prototype.crop = deprecate(crop, 'crop(position) is deprecated, use resize({ fit: "cover", position }) instead'); - Sharp.prototype.embed = deprecate(embed, 'embed(position) is deprecated, use resize({ fit: "contain", position }) instead'); - Sharp.prototype.max = deprecate(max, 'max() is deprecated, use resize({ fit: "inside" }) instead'); - Sharp.prototype.min = deprecate(min, 'min() is deprecated, use resize({ fit: "outside" }) instead'); - Sharp.prototype.ignoreAspectRatio = deprecate(ignoreAspectRatio, 'ignoreAspectRatio() is deprecated, use resize({ fit: "fill" }) instead'); - Sharp.prototype.withoutEnlargement = deprecate(withoutEnlargement, 'withoutEnlargement() is deprecated, use resize({ withoutEnlargement: true }) instead'); }; diff --git a/test/unit/deprecated-background.js b/test/unit/deprecated-background.js deleted file mode 100644 index a2b832bf..00000000 --- a/test/unit/deprecated-background.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -const assert = require('assert'); -const fixtures = require('../fixtures'); -const sharp = require('../../'); - -describe('Deprecated background', function () { - it('Flatten to RGB orange', function (done) { - sharp(fixtures.inputPngWithTransparency) - .flatten() - .background({ r: 255, g: 102, b: 0 }) - .resize(400, 300) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(400, info.width); - assert.strictEqual(300, info.height); - fixtures.assertSimilar(fixtures.expected('flatten-orange.jpg'), data, done); - }); - }); - - it('Flatten to CSS/hex orange', function (done) { - sharp(fixtures.inputPngWithTransparency) - .flatten() - .background('#ff6600') - .resize(400, 300) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(400, info.width); - assert.strictEqual(300, info.height); - fixtures.assertSimilar(fixtures.expected('flatten-orange.jpg'), data, done); - }); - }); - - it('Flatten 16-bit PNG with transparency to orange', function (done) { - const output = fixtures.path('output.flatten-rgb16-orange.jpg'); - sharp(fixtures.inputPngWithTransparency16bit) - .flatten() - .background({ r: 255, g: 102, b: 0 }) - .toFile(output, function (err, info) { - if (err) throw err; - assert.strictEqual(true, info.size > 0); - assert.strictEqual(32, info.width); - assert.strictEqual(32, info.height); - fixtures.assertMaxColourDistance(output, fixtures.expected('flatten-rgb16-orange.jpg'), 25); - done(); - }); - }); - - it('Ignored for JPEG', function (done) { - sharp(fixtures.inputJpg) - .background('#ff0000') - .flatten() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3, info.channels); - done(); - }); - }); - - it('extend all sides equally with RGB', function (done) { - sharp(fixtures.inputJpg) - .resize(120) - .background({ r: 255, g: 0, b: 0 }) - .extend(10) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(140, info.width); - assert.strictEqual(118, info.height); - fixtures.assertSimilar(fixtures.expected('extend-equal.jpg'), data, done); - }); - }); -}); diff --git a/test/unit/deprecated-crop.js b/test/unit/deprecated-crop.js deleted file mode 100644 index c477a02f..00000000 --- a/test/unit/deprecated-crop.js +++ /dev/null @@ -1,279 +0,0 @@ -'use strict'; - -const assert = require('assert'); - -const sharp = require('../../'); -const fixtures = require('../fixtures'); - -describe('Deprecated crop', function () { - [ - { - name: 'North', - width: 320, - height: 80, - gravity: sharp.gravity.north, - fixture: 'gravity-north.jpg' - }, - { - name: 'East', - width: 80, - height: 320, - gravity: sharp.gravity.east, - fixture: 'gravity-east.jpg' - }, - { - name: 'South', - width: 320, - height: 80, - gravity: sharp.gravity.south, - fixture: 'gravity-south.jpg' - }, - { - name: 'West', - width: 80, - height: 320, - gravity: sharp.gravity.west, - fixture: 'gravity-west.jpg' - }, - { - name: 'Center', - width: 320, - height: 80, - gravity: sharp.gravity.center, - fixture: 'gravity-center.jpg' - }, - { - name: 'Centre', - width: 80, - height: 320, - gravity: sharp.gravity.centre, - fixture: 'gravity-centre.jpg' - }, - { - name: 'Default (centre)', - width: 80, - height: 320, - gravity: undefined, - fixture: 'gravity-centre.jpg' - }, - { - name: 'Northeast', - width: 320, - height: 80, - gravity: sharp.gravity.northeast, - fixture: 'gravity-north.jpg' - }, - { - name: 'Northeast', - width: 80, - height: 320, - gravity: sharp.gravity.northeast, - fixture: 'gravity-east.jpg' - }, - { - name: 'Southeast', - width: 320, - height: 80, - gravity: sharp.gravity.southeast, - fixture: 'gravity-south.jpg' - }, - { - name: 'Southeast', - width: 80, - height: 320, - gravity: sharp.gravity.southeast, - fixture: 'gravity-east.jpg' - }, - { - name: 'Southwest', - width: 320, - height: 80, - gravity: sharp.gravity.southwest, - fixture: 'gravity-south.jpg' - }, - { - name: 'Southwest', - width: 80, - height: 320, - gravity: sharp.gravity.southwest, - fixture: 'gravity-west.jpg' - }, - { - name: 'Northwest', - width: 320, - height: 80, - gravity: sharp.gravity.northwest, - fixture: 'gravity-north.jpg' - }, - { - name: 'Northwest', - width: 80, - height: 320, - gravity: sharp.gravity.northwest, - fixture: 'gravity-west.jpg' - } - ].forEach(function (settings) { - it(settings.name + ' gravity', function (done) { - sharp(fixtures.inputJpg) - .resize(settings.width, settings.height) - .crop(settings.gravity) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(settings.width, info.width); - assert.strictEqual(settings.height, info.height); - fixtures.assertSimilar(fixtures.expected(settings.fixture), data, done); - }); - }); - }); - - it('Allows specifying the gravity as a string', function (done) { - sharp(fixtures.inputJpg) - .resize(80, 320) - .crop('east') - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(80, info.width); - assert.strictEqual(320, info.height); - fixtures.assertSimilar(fixtures.expected('gravity-east.jpg'), data, done); - }); - }); - - it('Invalid values fail', function () { - assert.throws(function () { - sharp().crop(9); - }, /Expected valid crop id\/name\/strategy for crop but received 9 of type number/); - assert.throws(function () { - sharp().crop(1.1); - }, /Expected valid crop id\/name\/strategy for crop but received 1.1 of type number/); - assert.throws(function () { - sharp().crop(-1); - }, /Expected valid crop id\/name\/strategy for crop but received -1 of type number/); - assert.throws(function () { - sharp().crop('zoinks'); - }, /Expected valid crop id\/name\/strategy for crop but received zoinks of type string/); - }); - - it('Uses default value when none specified', function () { - assert.doesNotThrow(function () { - sharp().crop(); - }); - }); - - it('Skip crop when post-resize dimensions are at target', function () { - return sharp(fixtures.inputJpg) - .resize(1600, 1200) - .toBuffer() - .then(function (input) { - return sharp(input) - .resize(1110) - .crop(sharp.strategy.attention) - .toBuffer({ resolveWithObject: true }) - .then(function (result) { - assert.strictEqual(1110, result.info.width); - assert.strictEqual(832, result.info.height); - assert.strictEqual(undefined, result.info.cropOffsetLeft); - assert.strictEqual(undefined, result.info.cropOffsetTop); - }); - }); - }); - - describe('Entropy-based strategy', function () { - it('JPEG', function (done) { - sharp(fixtures.inputJpg) - .resize(80, 320) - .crop(sharp.strategy.entropy) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3, info.channels); - assert.strictEqual(80, info.width); - assert.strictEqual(320, info.height); - assert.strictEqual(-117, info.cropOffsetLeft); - assert.strictEqual(0, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy-entropy.jpg'), data, done); - }); - }); - - it('PNG', function (done) { - sharp(fixtures.inputPngWithTransparency) - .resize(320, 80) - .crop(sharp.strategy.entropy) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('png', info.format); - assert.strictEqual(4, info.channels); - assert.strictEqual(320, info.width); - assert.strictEqual(80, info.height); - assert.strictEqual(0, info.cropOffsetLeft); - assert.strictEqual(-80, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); - }); - }); - - it('supports the strategy passed as a string', function (done) { - sharp(fixtures.inputPngWithTransparency) - .resize(320, 80) - .crop('entropy') - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('png', info.format); - assert.strictEqual(4, info.channels); - assert.strictEqual(320, info.width); - assert.strictEqual(80, info.height); - assert.strictEqual(0, info.cropOffsetLeft); - assert.strictEqual(-80, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); - }); - }); - }); - - describe('Attention strategy', function () { - it('JPEG', function (done) { - sharp(fixtures.inputJpg) - .resize(80, 320) - .crop(sharp.strategy.attention) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3, info.channels); - assert.strictEqual(80, info.width); - assert.strictEqual(320, info.height); - assert.strictEqual(-143, info.cropOffsetLeft); - assert.strictEqual(0, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy-attention.jpg'), data, done); - }); - }); - - it('PNG', function (done) { - sharp(fixtures.inputPngWithTransparency) - .resize(320, 80) - .crop(sharp.strategy.attention) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('png', info.format); - assert.strictEqual(4, info.channels); - assert.strictEqual(320, info.width); - assert.strictEqual(80, info.height); - assert.strictEqual(0, info.cropOffsetLeft); - assert.strictEqual(0, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); - }); - }); - - it('supports the strategy passed as a string', function (done) { - sharp(fixtures.inputPngWithTransparency) - .resize(320, 80) - .crop('attention') - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual('png', info.format); - assert.strictEqual(4, info.channels); - assert.strictEqual(320, info.width); - assert.strictEqual(80, info.height); - assert.strictEqual(0, info.cropOffsetLeft); - assert.strictEqual(0, info.cropOffsetTop); - fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); - }); - }); - }); -}); diff --git a/test/unit/deprecated-embed.js b/test/unit/deprecated-embed.js deleted file mode 100644 index 5c095048..00000000 --- a/test/unit/deprecated-embed.js +++ /dev/null @@ -1,440 +0,0 @@ -'use strict'; - -const assert = require('assert'); - -const sharp = require('../../'); -const fixtures = require('../fixtures'); - -describe('Deprecated embed', function () { - it('Allows specifying the gravity as a string', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 240) - .embed('center') - .png() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('embed-3-into-3.png'), data, done); - }); - }); - - it('JPEG within PNG, no alpha channel', function (done) { - sharp(fixtures.inputJpg) - .embed() - .resize(320, 240) - .png() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - assert.strictEqual(3, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-3-into-3.png'), data, done); - }); - }); - - it('JPEG within WebP, to include alpha channel', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 240) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed() - .webp() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('webp', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-3-into-4.webp'), data, done); - }); - }); - - it('PNG with alpha channel', function (done) { - sharp(fixtures.inputPngWithTransparency) - .resize(50, 50) - .embed() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(50, info.width); - assert.strictEqual(50, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-4-into-4.png'), data, done); - }); - }); - - it('16-bit PNG with alpha channel', function (done) { - sharp(fixtures.inputPngWithTransparency16bit) - .resize(32, 16) - .embed() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(32, info.width); - assert.strictEqual(16, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-16bit.png'), data, done); - }); - }); - - it('16-bit PNG with alpha channel onto RGBA', function (done) { - sharp(fixtures.inputPngWithTransparency16bit) - .resize(32, 16) - .embed() - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(32, info.width); - assert.strictEqual(16, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-16bit-rgba.png'), data, done); - }); - }); - - it('PNG with 2 channels', function (done) { - sharp(fixtures.inputPngWithGreyAlpha) - .resize(32, 16) - .embed() - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(32, info.width); - assert.strictEqual(16, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-2channel.png'), data, done); - }); - }); - - it('Enlarge and embed', function (done) { - sharp(fixtures.inputPngWithOneColor) - .embed() - .resize(320, 240) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - assert.strictEqual(3, info.channels); - fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done); - }); - }); - - it('Embed invalid param values should fail', function () { - assert.throws(function () { - sharp().embed(-1); - }); - assert.throws(function () { - sharp().embed(8.1); - }); - assert.throws(function () { - sharp().embed(9); - }); - assert.throws(function () { - sharp().embed(1000000); - }); - assert.throws(function () { - sharp().embed(false); - }); - assert.throws(function () { - sharp().embed('vallejo'); - }); - }); - - it('Embed gravity horizontal northwest', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.northwest) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a1-nw.png'), data, done); - }); - }); - - it('Embed gravity horizontal north', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.north) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a2-n.png'), data, done); - }); - }); - - it('Embed gravity horizontal northeast', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.northeast) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a3-ne.png'), data, done); - }); - }); - - it('Embed gravity horizontal east', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.east) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a4-e.png'), data, done); - }); - }); - - it('Embed gravity horizontal southeast', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.southeast) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a5-se.png'), data, done); - }); - }); - - it('Embed gravity horizontal south', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.south) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a6-s.png'), data, done); - }); - }); - - it('Embed gravity horizontal southwest', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.southwest) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a7-sw.png'), data, done); - }); - }); - - it('Embed gravity horizontal west', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.west) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a8-w.png'), data, done); - }); - }); - - it('Embed gravity horizontal center', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 100) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.center) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(100, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/a9-c.png'), data, done); - }); - }); - - it('Embed gravity vertical northwest', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.northwest) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/1-nw.png'), data, done); - }); - }); - - it('Embed gravity vertical north', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.north) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/2-n.png'), data, done); - }); - }); - - it('Embed gravity vertical northeast', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.northeast) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/3-ne.png'), data, done); - }); - }); - - it('Embed gravity vertical east', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.east) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/4-e.png'), data, done); - }); - }); - - it('Embed gravity vertical southeast', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.southeast) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/5-se.png'), data, done); - }); - }); - - it('Embed gravity vertical south', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.south) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/6-s.png'), data, done); - }); - }); - - it('Embed gravity vertical southwest', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.southwest) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/7-sw.png'), data, done); - }); - }); - - it('Embed gravity vertical west', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.west) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/8-w.png'), data, done); - }); - }); - - it('Embed gravity vertical center', function (done) { - sharp(fixtures.inputPngEmbed) - .resize(200, 200) - .background({ r: 0, g: 0, b: 0, alpha: 0 }) - .embed(sharp.gravity.center) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('png', info.format); - assert.strictEqual(200, info.width); - assert.strictEqual(200, info.height); - assert.strictEqual(4, info.channels); - fixtures.assertSimilar(fixtures.expected('./embedgravitybird/9-c.png'), data, done); - }); - }); -}); diff --git a/test/unit/deprecated-resize.js b/test/unit/deprecated-resize.js deleted file mode 100644 index 432c3392..00000000 --- a/test/unit/deprecated-resize.js +++ /dev/null @@ -1,261 +0,0 @@ -'use strict'; - -const assert = require('assert'); - -const sharp = require('../../'); -const fixtures = require('../fixtures'); - -describe('Deprecated resize-related functions', function () { - it('Max width or height considering ratio (portrait)', function (done) { - sharp(fixtures.inputTiff) - .resize(320, 320) - .max() - .jpeg() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(243, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Min width or height considering ratio (portrait)', function (done) { - sharp(fixtures.inputTiff) - .resize(320, 320) - .min() - .jpeg() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(422, info.height); - done(); - }); - }); - - it('Max width or height considering ratio (landscape)', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 320) - .max() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(261, info.height); - done(); - }); - }); - - it('Provide only one dimension with max, should default to crop', function (done) { - sharp(fixtures.inputJpg) - .resize(320) - .max() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(261, info.height); - done(); - }); - }); - - it('Min width or height considering ratio (landscape)', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 320) - .min() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(392, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Provide only one dimension with min, should default to crop', function (done) { - sharp(fixtures.inputJpg) - .resize(320) - .min() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(261, info.height); - done(); - }); - }); - - it('Do not enlarge when input width is already less than output width', function (done) { - sharp(fixtures.inputJpg) - .resize(2800) - .withoutEnlargement() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); - - it('Do not enlarge when input height is already less than output height', function (done) { - sharp(fixtures.inputJpg) - .resize(null, 2300) - .withoutEnlargement() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); - - it('Do enlarge when input width is less than output width', function (done) { - sharp(fixtures.inputJpg) - .resize(2800) - .withoutEnlargement(false) - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2800, info.width); - assert.strictEqual(2286, info.height); - done(); - }); - }); - - it('Downscale width and height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 320) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Downscale width, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(320) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); - - it('Downscale height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(null, 320) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Upscale width and height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(3000, 3000) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Upscale width, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(3000) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); - - it('Upscale height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(null, 3000) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Downscale width, upscale height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(320, 3000) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Upscale width, downscale height, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .resize(3000, 320) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Identity transform, ignoring aspect ratio', function (done) { - sharp(fixtures.inputJpg) - .ignoreAspectRatio() - .toBuffer(function (err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); -});