editly icon indicating copy to clipboard operation
editly copied to clipboard

How can I pass a parameter to a function?

Open bigturtle88 opened this issue 4 years ago • 5 comments

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 avatar Jan 26 '22 15:01 bigturtle88

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

bigturtle88 avatar Feb 09 '22 16:02 bigturtle88

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!

dennisideaonce avatar Feb 10 '22 02:02 dennisideaonce

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.

bigturtle88 avatar Feb 10 '22 08:02 bigturtle88

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.

dennisideaonce avatar Feb 11 '22 05:02 dennisideaonce

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);

mifi avatar Feb 27 '22 05:02 mifi