mifi / editly

Slick, declarative command line video editing & API
MIT License
4.64k stars 295 forks source link

How can I pass a parameter to a function? #176

Open bigturtle88 opened 2 years ago

bigturtle88 commented 2 years ago

How can I pass a parameter to a function? I need to pass my own text. I looked at the example but I can't figure out how to do it.

https://github.com/mifi/editly/blob/master/examples/customFabric.js

bigturtle88 commented 2 years ago

{ type: 'canvas', func: textEditor, text: title, params: params, } you just need to pass another parameter to the object.

dennisideaonce commented 2 years ago

Hi @bigturtle88 we are using the same tech stack: fabric js and editly. Probably you have used animate() function. Do you know the solution to this problem? I completely got stuck into this problem: https://github.com/mifi/editly/issues/180

Thank you in advance!

bigturtle88 commented 2 years ago

No, I don't use this feature.

editly({
  // fast: true,
  outPath: './customFabric.gif',
  // outPath: './customFabric.mp4',
  clips: [
    { duration: 2, layers: [{
type: 'canvas', func: textEditor, text: title, params: params,
}] },
  ],
}).catch(console.error);

I just pass one more parameter as in the example.

dennisideaonce commented 2 years ago

No no, in general, then how did you achieve animation. I am assuming you are trying to record fabric js animations into mp4. Any help is highly appreciated.

mifi commented 2 years ago

I think you can just send it in sometningl ike this:

const editly = require('..');

async function func(myParam, { width, height, fabric }) {
  async function onRender(progress, canvas) {
    canvas.backgroundColor = 'hsl(33, 100%, 50%)';

    const text = new fabric.Text(`PROGRESS\n${Math.floor(progress * 100)}%`, {
      originX: 'center',
      originY: 'center',
      left: width / 2,
      top: (height / 2) * (1 + (progress * 0.1 - 0.05)),
      fontSize: 20,
      textAlign: 'center',
      fill: 'white',
    });

    canvas.add(text);
  }

  function onClose() {
    // Cleanup if you initialized anything
  }

  return { onRender, onClose };
}

editly({
  // fast: true,
  outPath: './customFabric.gif',
  // outPath: './customFabric.mp4',
  clips: [
    { duration: 2, layers: [{ type: 'fabric', func: (params) => func(myParams, params) }] },
  ],
}).catch(console.error);