Figma Support Forum

Turn Solid Fill to Image fill and Populate

If I have a node with solid fill, I want to create a new ImagePaint fill it’s image hash with Unit8Array and replace the solid fill with the ImagePaint.

Em I approaching this correctly? The constructor is not clear to me.

  const tempPaint = new ImagePaint(); // this feels wrong
  const newPaint = JSON.parse(JSON.stringify(tempPaint));
  newPaint.imageHash = figma.createImage(unit8).hash;
  var newRect = figma.createRectangle();
  var newFills = [];
  newRect.fills = newFills;