Change the opacity / transparency of a layer and its sublayers:
$newOpacity = 50; $layer->opacity($newOpacity);
What we get:
1 - This method loops each pixel of the image to apply the transparency. Be carefull, it can be really long on large images !
2 - Always give a background color when getting the result if you don't want a transparent PNG... Otherwise, the transparency won't be saved !
Example if you want a JPEG or a GIF:
$result = $layer->getResult('ffffff'); // Giving a white background