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;
1 Like

Also ran into the same issue as you! I found out you can explicitly create a JSON object and populate it with the imageHash. Fields are listed here: Paint | Plugin API

const image = figma.createImage(new Uint8Array(imageData));
const newPaint = {
    type: "IMAGE",
    scaleMode: "FIT",
    imageHash: image.hash,
const newRect = figma.createRectangle();
const newFills = [];
newRect.fills = newFills;