How to use imageFill.scaleBehavior

A very noobiish question is coming. I stuck here with ImageFill module.

I want to fill a square with grabbed image. I managed to grab the image and fill it in the square dynamically, but cannot figure out how to use the imageFill.scaleBehavior.

In the typings repo, I found this line, which suggests to use cloneWithOverrides but can’t wrap my head around as I cant find it in documentation.

Any help regarding this issue will be appreciated.

Thanks in advance.

@bantya

1 Like

I think (though I just copied and pasted the docs during the Beta when I did these typings :wink:) that this means you can’t just change this property in an ImageFill of a node like

node.fill.scaleBehaviour = ImageFill.SCALE_COVER;

but you have to reassign it like

let fill = node.fill.clone();
fill.scaleBehaviour = ImageFill.SCALE_COVER;
node.fill = fill;

This is just a guess, though, which would “correspond” to other behaviours of the APis (cf. https://adobexdplatform.com/plugin-docs/reference/core/properties-with-object-values.html)…

Hope this helps,
Happy Coding,
Pablo :wink:

PS: It seems like I’ll have to update this section of the typings, when I find the time, though – the docs included in the typings seem a bit outdated :laughing:

2 Likes

There were some quirks with image fills in the beta versions of extensibility, but in the actual shipping APIs it’s as simple as:

let fill = node.fill;
fill.scaleBehavior = ImageFill.SCALE_COVER;
node.fill = fill;

That is, there’s no need to clone it (and there’s no “cloneWithOverrides” API anymore).

You do still need to re-invoke the fill property setter though, so you can’t just set node.fill.scaleBehavior = ... inline. That caveat is true of any scenegraph property whose value is an object – see " Properties with object values" in the docs.

Note that SCALE_COVER is the default, so there’s often no need to run the exact code shown above though…

2 Likes