diff --git a/examples/gradients.json5 b/examples/gradients.json5 new file mode 100644 index 0000000..676e2cd --- /dev/null +++ b/examples/gradients.json5 @@ -0,0 +1,12 @@ +{ + outPath: './gradients.mp4', + defaults: { + transition: { name: 'linearblur', duration: 0.1 }, + }, + clips: [ + { duration: 1, layers: [{ type: 'linear-gradient', colors: ['#02aab0', '#00cdac'] }] }, + { duration: 1, layers: [{ type: 'radial-gradient', colors: ['#b002aa', '#ac00cd'] }] }, + { duration: 1, layers: [{ type: 'linear-gradient' }] }, + { duration: 1, layers: [{ type: 'radial-gradient' }] }, + ], +} diff --git a/package.json b/package.json index 492f07d..682410e 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "canvas": "^2.6.1", "execa": "^4.0.0", - "fabric": "^3.6.3", + "fabric": "^4.1.0", "file-type": "^14.1.4", "file-url": "^3.0.0", "fs-extra": "^9.0.0", diff --git a/sources/fabricFrameSource.js b/sources/fabricFrameSource.js index 8b8211e..1d5ad67 100644 --- a/sources/fabricFrameSource.js +++ b/sources/fabricFrameSource.js @@ -152,19 +152,21 @@ async function radialGradientFrameSource({ width, height, params }) { const cx = 0.5 * rect.width; const cy = 0.5 * rect.height; - rect.setGradient('fill', { + rect.set('fill', new fabric.Gradient({ type: 'radial', - r1, - r2, - x1: cx, - y1: cy, - x2: cx, - y2: cy, - colorStops: { - 0: colors[0], - 1: colors[1], + coords: { + r1, + r2, + x1: cx, + y1: cy, + x2: cx, + y2: cy, }, - }); + colorStops: [ + { offset: 0, color: colors[0] }, + { offset: 1, color: colors[1] }, + ], + })); canvas.add(rect); } @@ -181,16 +183,18 @@ async function linearGradientFrameSource({ width, height, params }) { async function onRender(progress, canvas) { const rect = getRekt(width, height); - rect.setGradient('fill', { - x1: 0, - y1: 0, - x2: width, - y2: height, - colorStops: { - 0: colors[0], - 1: colors[1], + rect.set('fill', new fabric.Gradient({ + coords: { + x1: 0, + y1: 0, + x2: width, + y2: height, }, - }); + colorStops: [ + { offset: 0, color: colors[0] }, + { offset: 1, color: colors[1] }, + ], + })); rect.rotate(progress * 30); canvas.add(rect);