Skip to content

Commit adae0a0

Browse files
authored
Reject join.across and join.shim for animated joins (#4634)
1 parent 857281a commit adae0a0

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎docs/src/content/docs/api-constructor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages`
7676
| [options.text.wrap] | <code>string</code> | <code>&quot;&#x27;word&#x27;&quot;</code> | word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'. |
7777
| [options.join] | <code>Object</code> | | describes how an array of input images should be joined. |
7878
| [options.join.across] | <code>number</code> | <code>1</code> | number of images to join horizontally. |
79-
| [options.join.animated] | <code>boolean</code> | <code>false</code> | set this to `true` to join the images as an animated image. |
79+
| [options.join.animated] | <code>boolean</code> | <code>false</code> | set this to `true` to join the images as an animated image, cannot be used with `across` or `shim`. |
8080
| [options.join.shim] | <code>number</code> | <code>0</code> | number of pixels to insert between joined images. |
8181
| [options.join.background] | <code>string</code> \| <code>Object</code> | | parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. |
8282
| [options.join.halign] | <code>string</code> | <code>&quot;&#x27;left&#x27;&quot;</code> | horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`). |

‎lib/constructor.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ const queueListener = (queueLength) => {
202202
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'.
203203
* @param {Object} [options.join] - describes how an array of input images should be joined.
204204
* @param {number} [options.join.across=1] - number of images to join horizontally.
205-
* @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image.
205+
* @param {boolean} [options.join.animated=false] - set this to `true` to join the images as an animated image, cannot be used with `across` or `shim`.
206206
* @param {number} [options.join.shim=0] - number of pixels to insert between joined images.
207207
* @param {string|Object} [options.join.background] - parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
208208
* @param {string} [options.join.halign='left'] - horizontal alignment style for images joined horizontally (`'left'`, `'centre'`, `'center'`, `'right'`).

‎lib/input.mjs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
511511
throw is.invalidParameterError('join.valign', 'valid alignment', inputOptions.join.valign);
512512
}
513513
}
514+
if (inputDescriptor.joinAnimated && (inputDescriptor.joinAcross > 1 || inputDescriptor.joinShim > 0)) {
515+
throw new Error('Expected neither join.across nor join.shim when join.animated is set');
516+
}
514517
} else {
515518
throw new Error('Expected input to be an array of images to join');
516519
}

‎test/unit/join.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ suite('Join input images together', () => {
124124
/Expected integer between 0 and 100000 for join.shim but received -1 of type number/
125125
);
126126
});
127+
test('Animated with across throws', (t) => {
128+
t.plan(2);
129+
t.assert.throws(
130+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { join: { animated: true, across: 2 } }),
131+
/Expected neither join.across nor join.shim when join.animated is set/
132+
);
133+
t.assert.doesNotThrow(
134+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { join: { animated: true, across: 1 } })
135+
);
136+
});
137+
test('Animated with shim throws', (t) => {
138+
t.plan(2);
139+
t.assert.throws(
140+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { join: { animated: true, shim: 4 } }),
141+
/Expected neither join.across nor join.shim when join.animated is set/
142+
);
143+
t.assert.doesNotThrow(
144+
() => sharp([fixtures.inputJpg, fixtures.inputJpg], { join: { animated: true, shim: 0 } })
145+
);
146+
});
127147
test('Invalid halign', (t) => {
128148
t.plan(1);
129149
t.assert.throws(

0 commit comments

Comments
 (0)