Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Text on Layers
-
hi
i was trying to blend a text with an image and use it as an image of a layer. i opened the background image, wrote a text on it using ImageDraw.text and loaded it as layer's image with load_pil_image.
but it seems that quality of the text is poorer that a text directly drawn on the scene using scene.text.
1- is there a solution for that?
2- while i was searching for a solution i found the TextLayer command in the Cascade example, for which no documentation seems to be available. can i use this to solve my problem?
thnx
-
When you use ImageDraw on a retina device, you might need to double the width and the height of your image to make it looks crisp. The scene module uses a "point" coordinate system (on retina 1 point = 2 pixels), while ImageDraw uses normal pixels.
The TextLayer class is currently undocumented, but pretty simple to use. It's basically just a layer that uses the result from render_text() as its image. There isn't much more to it than what you see in the examples, in fact, this is the entire source code of the class:
<pre>
class TextLayer (Layer):
def init(self, text, font, font_size):
Layer.init(self)
img, size = render_text(text, font, font_size)
self.image = img
self.frame = Rect(0, 0, size.w, size.h)
</pre>To combine it with an image, you could add a TextLayer as a sublayer of an image layer, using the add_layer() method.
-
You can simply set the <code>tint</code> property of the TextLayer to set it to a different color, e.g. for red text:
<pre>text_layer = ...
text_layer.tint = Color(1, 0, 0)</pre>