Skip to content

Commit 4346454

Browse files
authored
Merge pull request #238 from Kalo0m/feat/translation-Ken-Burns
add right/left parameters - translations
2 parents 964ae7c + c4948fc commit 4346454

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ See [position.json5](examples/position.json5)
399399

400400
| Parameter | Description | Default | |
401401
|-|-|-|-|
402-
| `zoomDirection` | Zoom direction for Ken Burns effect: `in`, `out` or `null` to disable | | |
402+
| `zoomDirection` | Zoom direction for Ken Burns effect: `in`, `out`, `left`, `right` or `null` to disable | | |
403403
| `zoomAmount` | Zoom amount for Ken Burns effect | `0.1` | |
404404

405405
## Docker

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ declare namespace Editly {
230230
* Zoom direction for Ken Burns effect.
231231
* Use `null` to disable.
232232
*/
233-
zoomDirection?: 'in' | 'out' | null;
233+
zoomDirection?: 'in' | 'out' | 'left' | `right` | null;
234234

235235
/**
236236
* Zoom amount for Ken Burns effect.

sources/fabric/fabricFrameSources.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ const loadImage = async (pathOrUrl) => new Promise((resolve) => fabric.util.load
1414

1515
function getZoomParams({ progress, zoomDirection, zoomAmount }) {
1616
let scaleFactor = 1;
17+
if (zoomDirection === 'left' || zoomDirection === 'right') return 1.3;
1718
if (zoomDirection === 'in') scaleFactor = (1 + zoomAmount * progress);
1819
else if (zoomDirection === 'out') scaleFactor = (1 + zoomAmount * (1 - progress));
1920
return scaleFactor;
2021
}
2122

23+
function getTranslationParams({ progress, zoomDirection, zoomAmount }) {
24+
let translation = 0;
25+
const range = zoomAmount * 1000;
26+
27+
if (zoomDirection === 'right') translation = (progress) * range - range / 2;
28+
else if (zoomDirection === 'left') translation = (100 - progress * 100) * range - range / 2;
29+
30+
return translation;
31+
}
32+
2233
export async function imageFrameSource({ verbose, params, width, height }) {
2334
const { path, zoomDirection = 'in', zoomAmount = 0.1, resizeMode = 'contain-blur' } = params;
2435

@@ -46,10 +57,13 @@ export async function imageFrameSource({ verbose, params, width, height }) {
4657
const img = createImg();
4758

4859
const scaleFactor = getZoomParams({ progress, zoomDirection, zoomAmount });
60+
const translationParams = getTranslationParams({ progress, zoomDirection, zoomAmount });
4961

5062
const ratioW = width / img.width;
5163
const ratioH = height / img.height;
5264

65+
img.left = width / 2 + translationParams;
66+
5367
if (['contain', 'contain-blur'].includes(resizeMode)) {
5468
if (ratioW > ratioH) {
5569
img.scaleToHeight(height * scaleFactor);
@@ -230,6 +244,9 @@ export async function imageOverlayFrameSource({ params, width, height }) {
230244
async function onRender(progress, canvas) {
231245
const scaleFactor = getZoomParams({ progress, zoomDirection, zoomAmount });
232246

247+
const translationParams = getTranslationParams({ progress, zoomDirection, zoomAmount });
248+
img.left = width / 2 + translationParams;
249+
233250
if (relWidth != null) {
234251
img.scaleToWidth(relWidth * width * scaleFactor);
235252
} else if (relHeight != null) {
@@ -257,6 +274,8 @@ export async function titleFrameSource({ width, height, params }) {
257274

258275
const scaleFactor = getZoomParams({ progress, zoomDirection, zoomAmount });
259276

277+
const translationParams = getTranslationParams({ progress, zoomDirection, zoomAmount });
278+
260279
const textBox = new fabric.Textbox(text, {
261280
fill: textColor,
262281
fontFamily,
@@ -273,7 +292,7 @@ export async function titleFrameSource({ width, height, params }) {
273292
textImage.set({
274293
originX,
275294
originY,
276-
left,
295+
left: left + translationParams,
277296
top,
278297
scaleX: scaleFactor,
279298
scaleY: scaleFactor,

0 commit comments

Comments
 (0)