mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Sends width and height as another parameter to the callback. Fixes issue #67
This commit is contained in:
@@ -21,8 +21,10 @@ var inputJpgWithExif = path.join(fixturesPath, "Landscape_8.jpg"); // https://gi
|
||||
async.series([
|
||||
// Resize with exact crop
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(320, 240).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(320, 240).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -33,8 +35,10 @@ async.series([
|
||||
},
|
||||
// Resize to fixed width
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(320).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(320).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -45,8 +49,10 @@ async.series([
|
||||
},
|
||||
// Resize to fixed height
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(null, 320).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(null, 320).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(391, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(391, features.width);
|
||||
@@ -69,8 +75,10 @@ async.series([
|
||||
},
|
||||
// Upscale
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(3000).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(3000).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3000, info.width);
|
||||
assert.strictEqual(2449, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(3000, features.width);
|
||||
@@ -118,8 +126,10 @@ async.series([
|
||||
},
|
||||
// Resize to max width or height considering ratio (landscape)
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(320, 320).max().toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(320, 320).max().toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -130,8 +140,10 @@ async.series([
|
||||
},
|
||||
// Resize to max width or height considering ratio (portrait)
|
||||
function(done) {
|
||||
sharp(inputTiff).resize(320, 320).max().toFile(outputJpg, function(err) {
|
||||
sharp(inputTiff).resize(320, 320).max().toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(243, info.width);
|
||||
assert.strictEqual(320, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(243, features.width);
|
||||
@@ -142,8 +154,10 @@ async.series([
|
||||
},
|
||||
// Attempt to resize to max but only provide one dimension, so should default to crop
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(320).max().toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(320).max().toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -161,8 +175,10 @@ async.series([
|
||||
},
|
||||
// Rotate by 90 degrees, respecting output input size
|
||||
function(done) {
|
||||
sharp(inputJpg).rotate(90).resize(320, 240).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).rotate(90).resize(320, 240).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -173,8 +189,10 @@ async.series([
|
||||
},
|
||||
// Input image has Orientation EXIF tag but do not rotate output
|
||||
function(done) {
|
||||
sharp(inputJpgWithExif).resize(320).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpgWithExif).resize(320).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(426, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -185,8 +203,10 @@ async.series([
|
||||
},
|
||||
// Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate
|
||||
function(done) {
|
||||
sharp(inputJpgWithExif).rotate().resize(320).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpgWithExif).rotate().resize(320).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -197,8 +217,10 @@ async.series([
|
||||
},
|
||||
// Attempt to auto-rotate using image that has no EXIF
|
||||
function(done) {
|
||||
sharp(inputJpg).rotate().resize(320).toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).rotate().resize(320).toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(261, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(320, features.width);
|
||||
@@ -219,8 +241,10 @@ async.series([
|
||||
},
|
||||
// Do not enlarge the output if the input width is already less than the output width
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(2800).withoutEnlargement().toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(2800).withoutEnlargement().toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2725, features.width);
|
||||
@@ -231,8 +255,10 @@ async.series([
|
||||
},
|
||||
// Do not enlarge the output if the input height is already less than the output height
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(null, 2300).withoutEnlargement().toFile(outputJpg, function(err) {
|
||||
sharp(inputJpg).resize(null, 2300).withoutEnlargement().toFile(outputJpg, function(err, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2725, info.width);
|
||||
assert.strictEqual(2225, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(2725, features.width);
|
||||
@@ -243,7 +269,9 @@ async.series([
|
||||
},
|
||||
// Promises/A+
|
||||
function(done) {
|
||||
sharp(inputJpg).resize(320, 240).toFile(outputJpg).then(function() {
|
||||
sharp(inputJpg).resize(320, 240).toFile(outputJpg).then(function(info) {
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
imagemagick.identify(outputJpg, function(err, features) {
|
||||
assert.strictEqual(320, features.width);
|
||||
assert.strictEqual(240, features.height);
|
||||
|
||||
Reference in New Issue
Block a user