https://github.com/ianbutterworth/basictextrender.jl
Makes pixels from strings in a very basic way
https://github.com/ianbutterworth/basictextrender.jl
Last synced: 3 months ago
JSON representation
Makes pixels from strings in a very basic way
- Host: GitHub
- URL: https://github.com/ianbutterworth/basictextrender.jl
- Owner: IanButterworth
- License: mit
- Created: 2019-11-08T01:56:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-09T22:49:39.000Z (over 5 years ago)
- Last Synced: 2025-02-23T06:43:49.358Z (3 months ago)
- Language: Julia
- Size: 1.53 MB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BasicTextRender.jl
Warning.. very basic.. More of an experiment.. Concatenates characters from pre-rendered lookup images, then resizes and colors. 100% julia, no libs. Gets blurry if font height is greater than ~90 pixels.
Provides `rendertext` for generating a rendered image of a string and
`overlaytext!` for directly overlaying text on a loaded image.Currently built to support truly monospaced fonts only, and Courier is the only font that is provided.
(other open source licensed fonts welcome via PR, see `gen/makeCharLookups.jl`)## Generating rendered text
```julia
> using BasicTextRender
> img = rendertext("Hello world", height=50)
50×316 Array{RGBA{Float64},2} with eltype RGBA{Float64}:
...
> using FileIO
> save("img.png", img)
```
```julia
using BasicTextRender, ColorTypes
img = rendertext("Hello world", height=30, color=RGBA(1.0,0.0,0.0,1.0), backgroundColor=RGBA(1.0,1.0,0.0,1.0))
```
## Overlaying text on a loaded image
```julia
img = rand(RGBA{Float64},80,700)
overlaytext!(img, "BasicTextRender.jl", 60, (10,40))
save("logo.png", img)
```
## Speed (slow then fast-ish)
The first time `rendertext` runs it should take about 5 seconds, as it loads the
character lookup table, but subsequent calls for the same scale and font will be fast.```julia
using BenchmarkTools
@btime rendertext("Hello world", height=30) #599.991 μs (352 allocations: 2.28 MiB)
```