How can I set the transparency/opacity and color of a shape in google slides using Google Apps Script?

1k views Asked by At

I am trying to set the colour of a shape on google slides using AppsScript. I am able to achieve this but realise that transparency values are 0. How can I set a new colour and the transparency value? I have tried to add transparency direct to the hex i.e. #F2E4002B for 95% Transparency - but this fails.

function colourForeground(aShape) {

let aColour = "#E4002B"

  aShape.getText().getTextStyle().setForegroundColor(aColour);

}
1

There are 1 answers

0
Marios On BEST ANSWER

You can use setSolidFill(hexString,alpha) to set both the color and the opacity of the shape.

In the following example, we set hexString to #E4002B and alpha to 95% or 0.95:

function colourForeground(aShape) {

let aColour = "#E4002B";
aShape.getFill().setSolidFill(aColour,0.95);

}

The second argument of this function (alpha) controls the opacity and takes values between 0 and 1.