Generating text over transparent background
See original GitHub issueIt looks like one of the most basic tasks and yet it seems quite hard to do at least without reading through all of the documentation and looking at only the related methods and classes.
def output(filename, text, color):
image, feedback = pyvips.Image.text(
text, font='Liberation-Sans-Narrow', width=32, height=32,
autofit_dpi=True)
image = image.colourspace('srgb')
image = image.addalpha()
image = image.ifthenelse([0, 0, 0, 255], [255, 255, 255, 0], blend=True)
image.write_to_file(f'{DIR}/{filename}.png')
I guess I’m not working correctly with ifthenelse. But what are the right values to make the image transparent? Where is the alpha channel supposed to be?
Also, the resulting image is not 32x32, it may be good to add hints on how to make it the required size somewhere around here.
Additional context #203 https://github.com/libvips/libvips/issues/1208
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Transparent Text Generator - Create transparent PNG images ...
Free Online Transparent Text Editor. Design high quality transparent texts as PNG images.
Read more >Simple Text Logo Generator
Simple Text Logo Generator. Blue Shadow Plain Gradient. Move and rotate elements by dragging them. Resize by dragging this corner. Rendered Image Rendering....
Read more >Text-Only PNG with a Transparent Background for Printing
Quick steps for creating and saving text on a transparent background: · Open a blank canvas in the dimensions you desire. · In...
Read more >Free Online Transparent Image & Text Maker Tool - Canva
1. Open Canva. Start a new project when you upload an image file right away or choose a design template. You can also...
Read more >Text To Image Generator - GeneratorMix
The generate text to an image, type your text below, select what font you would like to use, set some other options and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
a.embed(x, y, width, height)
will positiona
at (x, y) within an image of size (width, height).Hello again, you could make this a little simpler: use the text for the alpha and have a solid colour in RGB.
For example:
The
gravity
will expand the alpha up to 32x32 if it’s smaller.text
uses 0 - 255 for black - white. If you want to make the text semi-transparent, you’ll need to set a smaller range, perhaps 0 - 64? You could write: