-
Notifications
You must be signed in to change notification settings - Fork 62
-
I'm trying to figure out how to load a font from a path, as this will be running on ubuntu and i dont want to mess with trying to install fonts when I deploy. Id rather use a few fonts in the git repo
FONTS = [
{ name: "Akira Expanded Not-Rotated 12", filename: "akira.otf", spacing: -25 },
{ name: "Vogue Regular", filename: "vogue.ttf", spacing: -25 },
]
font = FONTS.sample
text = Vips::Image.text "test text",
fontfile: Rails.root.join("lib/assets/fonts/#{font[:filename]}").to_path,
font: font[:name],
width: render_width,
height: render_height,
spacing: font[:spacing]
This always renders Arial no matter what. I can tell its loading the proper file as when i put a bogus filename it expectedly errors... yet there is no error about "font not found from loaded files" so it makes it difficult to debug if i have the name correct, and something else is wrong... or if the name is just wrong.
Ive tried...
Vogue, Regular
Voge
Vogue Regular
etc
Do I need some extra library installed?
Beta Was this translation helpful? Give feedback.
All reactions
Yes, I think cairo on mac is using the native macOS font renderer, so you can't load fonts dynamically, you have to install them. It should work on ubuntu though.
Replies: 1 comment 6 replies
-
Hello @9mm,
It should work (I think?). You can use fc-scan to get the name from a font file, for example:
$ fc-scan MissFajardose-Regular.ttf
Pattern has 28 elts (size 32)
family: "Miss Fajardose"(s)
familylang: "en"(s)
style: "Regular"(s)
stylelang: "en"(s)
fullname: "Miss Fajardose Regular"(s)
...
So I can use:
$ vips text x.png "Hello World" --fontfile MissFajardose-Regular.ttf --font "Miss Fajardose" --dpi 600
There's also FC_DEBUG to debug font loading issues.
Beta Was this translation helpful? Give feedback.
All reactions
-
Just set the env var before running the command, for example:
$ FC_DEBUG=1 vips text x.png "Hello World" --fontfile MissFajardose-Regular.ttf --font "Miss Fajardose" --dpi 600
It's incredibly chatty and it'll take a while to read the output, but it should have the info you need.
See:
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html#DEBUG
Beta Was this translation helpful? Give feedback.
All reactions
-
hmmm.. it just exits immediately with no error or output
FC_DEBUG=1 vips text x.png "Hello World" --fontfile baberry.otf --font "Baberry" --dpi 600
FC_DEBUG=1
Is there some kind of other package i need to install? all i did was brew install vips on OSX
Beta Was this translation helpful? Give feedback.
All reactions
-
Ah you said you were on ubuntu. I don't know if macOS can use fontconfig in the same way, I'll check.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes, I think cairo on mac is using the native macOS font renderer, so you can't load fonts dynamically, you have to install them. It should work on ubuntu though.
Beta Was this translation helpful? Give feedback.
All reactions
-
Ughh I'm very sorry about that. I meant to type "ubuntu in production and OSX locally" but got sidetracked halfway through my sentence.
Ok thank you, i'll just install them but try on ubuntu. I really appreciate it
Beta Was this translation helpful? Give feedback.