Forum Archive

Size of layer image

jugisto135

Is there a way to set the size of a layer's image in the scene module? I have something like this.

self.layer.image = render_text('foo')[0]

This will stretch the given text out of proportions, depending on the size of the layer. But I have fixed size layers that should have centered texts. How can I achieve this?

ccc

One possible solution:

Create your fixed size layer and add a sublayer to it that is rightsized to your image...

(imageName, imageSize) = render_text('foo')
innerLayer = Layer(Rect(0, 0, imageSize.w, imageSize.h))
#innerLayer = Layer(Rect(0, 0, *imageSize)  # would also work
innerLayer.image = imageName
self.layer.add_layer(innerLayer)
innerLayer.center(self.layer.center())
jugisto135

Thanks, ccc.