Skip to content

Commit f88cd56

Browse files
authored
Ensure all input options apply to joined images (#4643)
1 parent 8032321 commit f88cd56

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎lib/input.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
9494
// Join images together
9595
if (!this.options.joining) {
9696
this.options.joining = true;
97-
this.options.join = input.map(i => this._createInputDescriptor(i));
97+
// Apply input options to each image being joined
98+
const joinOptions = is.object(inputOptions) ? _inputOptionsFromObject(inputOptions) : undefined;
99+
this.options.join = input.map(i => is.plainObject(i)
100+
? this._createInputDescriptor({ ...joinOptions, ...i })
101+
: this._createInputDescriptor(i, joinOptions));
98102
} else {
99103
throw new Error('Recursive join is unsupported');
100104
}

‎test/unit/join.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,27 @@ suite('Join input images together', () => {
151151
/Expected valid alignment for join.halign but received fail of type string/
152152
);
153153
});
154+
test('Limits apply to each image being joined', async (t) => {
155+
t.plan(2);
156+
await t.assert.rejects(
157+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { limitInputPixels: 1 }).toBuffer(),
158+
/Input image exceeds pixel limit/
159+
);
160+
await t.assert.rejects(
161+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { limitInputChannels: 1 }).toBuffer(),
162+
/Input image exceeds channel limit/
163+
);
164+
});
165+
test('Input options apply to each image being joined', async (t) => {
166+
t.plan(2);
167+
await t.assert.rejects(
168+
() => sharp([fixtures.inputJpgTruncated, fixtures.inputJpg]).toBuffer(),
169+
/VipsJpeg: premature end of/
170+
);
171+
const { info } = await sharp([fixtures.inputJpgTruncated, fixtures.inputJpg], { failOn: 'none' })
172+
.toBuffer({ resolveWithObject: true });
173+
t.assert.strictEqual(info.format, 'png');
174+
});
154175
test('Invalid valign', (t) => {
155176
t.plan(1);
156177
t.assert.throws(

0 commit comments

Comments
 (0)