mirror of
https://github.com/lovell/sharp.git
synced 2025-07-27 10:02:26 +02:00
Add resized images to rotation test
To trigger the "shouldRotateBefore" code path.
This commit is contained in:
parent
0263e6eaac
commit
bc42109382
@ -63,41 +63,46 @@ describe('Rotation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
[90, 180, 270, 45].forEach(function (angle) {
|
[true, false].forEach((doResize) => {
|
||||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
[90, 180, 270, 45].forEach(function (angle) {
|
||||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_rotate${angle}-out.jpg`);
|
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle}`, function (done) {
|
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_rotate${angle}-out.jpg`);
|
||||||
const [width, height] = angle === 45 ? [742, 742] : [inputWidth, inputHeight];
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then rotate ${angle} ${doResize ? 'and resize' : ''}`, function (done) {
|
||||||
const [expectedWidth, expectedHeight] = angle % 180 === 0 ? [width, height] : [height, width];
|
const [width, height] = (angle === 45 ? [742, 742] : [inputWidth, inputHeight]).map((x) => doResize ? Math.floor(x / 1.875) : x);
|
||||||
|
const [expectedWidth, expectedHeight] = angle % 180 === 0 ? [width, height] : [height, width];
|
||||||
|
|
||||||
sharp(input)
|
const img = sharp(input)
|
||||||
.rotate()
|
.rotate()
|
||||||
.rotate(angle)
|
.rotate(angle);
|
||||||
.toBuffer(function (err, data, info) {
|
doResize && img.resize(expectedWidth);
|
||||||
|
|
||||||
|
img.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(info.width, expectedWidth);
|
assert.strictEqual(info.width, expectedWidth);
|
||||||
assert.strictEqual(info.height, expectedHeight);
|
assert.strictEqual(info.height, expectedHeight);
|
||||||
fixtures.assertSimilar(expectedOutput, data, done);
|
fixtures.assertSimilar(expectedOutput, data, done);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
[[true, true], [true, false], [false, true]].forEach(function ([flip, flop]) {
|
[[true, true], [true, false], [false, true]].forEach(function ([flip, flop]) {
|
||||||
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
const [inputWidth, inputHeight] = orientation === 'Landscape' ? [600, 450] : [450, 600];
|
||||||
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
const flipFlopFileName = [flip && 'flip', flop && 'flop'].filter(Boolean).join('_');
|
||||||
const flipFlopTestName = [flip && 'flip', flop && 'flop'].filter(Boolean).join(' & ');
|
const flipFlopTestName = [flip && 'flip', flop && 'flop'].filter(Boolean).join(' & ');
|
||||||
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName}`, function (done) {
|
it(`${orientation} image with EXIF Orientation ${exifTag}: Auto-rotate then ${flipFlopTestName} ${doResize ? 'and resize' : ''}`, function (done) {
|
||||||
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
const expectedOutput = fixtures.expected(`${orientation}_${exifTag}_${flipFlopFileName}-out.jpg`);
|
||||||
|
|
||||||
const img = sharp(input).rotate();
|
const img = sharp(input).rotate();
|
||||||
flip && img.flip();
|
flip && img.flip();
|
||||||
flop && img.flop();
|
flop && img.flop();
|
||||||
|
doResize && img.resize(orientation === 'Landscape' ? 320 : 240);
|
||||||
|
|
||||||
img.toBuffer(function (err, data, info) {
|
img.toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(info.width, inputWidth);
|
assert.strictEqual(info.width, inputWidth / (doResize ? 1.875 : 1));
|
||||||
assert.strictEqual(info.height, inputHeight);
|
assert.strictEqual(info.height, inputHeight / (doResize ? 1.875 : 1));
|
||||||
fixtures.assertSimilar(expectedOutput, data, done);
|
fixtures.assertSimilar(expectedOutput, data, done);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user