Skip to content

Commit 6bc7a9d

Browse files
committed
check the source of composite
1 parent f868f33 commit 6bc7a9d

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

‎src/image.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,7 @@ export class Image {
14341434
composite(source: Image, options?: CompositeOptions): this;
14351435
composite(source: Image, options: CompositeOptions = {}): this {
14361436
checkOptions(options, 'composite(source, { x: 10, y: 20 })');
1437+
if (!(source instanceof Image)) throw new TypeError('composite() takes an Image as its source, like image.composite(logo, { x: 10, y: 20 })');
14371438
const { opacity = 1, mode = 'normal' } = options;
14381439
let x = options.x ?? 0, y = options.y ?? 0;
14391440
x = Math.trunc(finite(x, 'x'));

‎tests/option-checks.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const rejects = async (name, fn, Type, pattern) => {
8383
await rejects('resize mode', () => image.clone().resize(4, 4, {mode: 'lanczos'}), TypeError, /resize mode must be 'nearest-neighbor', 'bilinear', 'bicubic' or 'area', not 'lanczos'/);
8484
await rejects('scale mode', () => image.clone().scale(2, {mode: 'lanczos'}), TypeError, /resize mode must be/);
8585
await rejects('blend mode', () => image.clone().composite(image, {mode: 'nope'}), TypeError, /blend mode must be/);
86+
for (const source of [undefined, null, {}, 5, new Frame(image)]) await rejects(`composite source ${String(source)}`, () => image.clone().composite(source), TypeError, /takes an Image/);
8687

8788
// scale() doesn't shrink a side below one pixel, like resize({ width }) keeping the aspect ratio
8889
{

0 commit comments

Comments
 (0)