Performance of ImageDraw::text() and potential use of FTC_Manager()
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 32/100
- Issue type
- Feature
- Clarity
- Needs clarification
- Activity status
- Stale
- Domain
- computer-graphics, performance
Research direction
Start with the ImageDraw::draw_text → ImageFont::getmask2 call path and inspect imagingft.c, especially font_getsize, font_render, and text_layout_raqm. Review the reported profiling results and FreeType's FTC_Manager documentation before deciding whether glyph caching fits Pillow's design. Done would require an agreed implementation scope and measured performance evidence for repeated dynamic text rendering.
Written by the indexing model from the issue text.
Description
What did you do?
Used Pillow to render frames outputting to ffmpeg - in project https://github.com/time4tea/gopro-dashboard-overlay
Pillow is great!
I'm trying to render frames as quickly as possible, as there are many frames to render in a 1 or 2 hour video - even at 10 frames/second
I'm using the text facilities of Pillow to render text into an Image. I cache text images where possible - so rendering fixed text strings is very quick - however, with a dynamic text string, such as a datetime or GPS location - caching isn't so effective.
Looking at the call stack of drawing some text.. it seems to look something like:
ImageDraw::draw_text()
ImageFont::getmask2()
Font::getsize() - implemented in imagingft.c font_getsize
Font::render() - implemented in imagingft.c font_render
When you call these functions a lot - as I do - it becomes clear that these functions probably do a lot of similar work - in a python profile of a run of my software (there are multiple call routes here so don't worry they don't all add up!)
draw_text -> 2077 calls 8259ms
getmask2 -> 2076 calls 7567ms
Font::getsize -> 2595 calls 4171ms
Font::render -> 2076 calls 4195ms
Looking at imagingft.c, - they both seem to call (in my case) text_layout_raqm, which, I'm guessing calls through to FT to get the glyphs for the given string - allowing for ligatures/kerning etc.
I was wondering... FT seems to allow for glyph caching using FTC_Manager - is there any appetite for adding support for this?
I think that, in the case of rendering lots of frames of text, it has the possibility of adding quite a bit of performance. (Which is probably not a major goal for Pillow, totally fair!)
For example, rendering a compass widget using Pillow, with a few open and filled circles, lots of compass lines, and bilinear resize for AA takes about 2.6ms, but when adding in 4 characters for "N", "S","E", "W" - takes 13ms. (I could optimise this particular use case, its just an example of how the text rendering compares to the rest of Pillow)
Thanks for reading this far!
Thanks for a super library!
- Dominant language
- Python
- Stars
- 14k
- Forks
- 2.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 205
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-pillow/Pillow
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
python-pillow/Pillow#10590 ·
Maintainers usually reply within 1 day
-
Image.thumbnail() raises ZeroDivisionError when the target height is 0Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
python-pillow/Pillow#10589 ·
Maintainers usually reply within 1 day
-
Sun raster files with RLE encoding and odd-width rows decode shiftedPossibly taken @PerryLink claimed this 21 days ago. Open🤖-assisted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-pillow/Pillow#10370 · 3 comments ·
Maintainers usually reply within 1 day
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildPossibly taken @Syamjith-NK claimed this 85 days ago. OpenDocumentation Font Rendering PNG Third Party Framework
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-pillow/Pillow#9907 · 3 comments ·
Maintainers usually reply within 1 day
-
Example code in ImageText documentation makes incorrect use of get_bbox()Possibly taken @mmporong claimed this 1 day ago. OpenDocumentation
Difficulty 1/5 Under an hour Newbie friendliness 25/100
python-pillow/Pillow#10583 · 1 comment ·
Maintainers usually reply within 1 day
All issues in python-pillow/Pillow
Similar issues
-
pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pydantic/pydantic-ai#14187 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
[Bug]: legacy_json_to_doc crashes on persisted docs with "relationships": nullPossibly taken @Harsh23Kashyap claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 88/100
run-llama/llama_index#24392 ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
pathintegral-institute/mcpm.sh#568 ·
Maintainers usually reply within 21 days