Reputation: 6316
I'm working with some TTF files in PHP. I'm using this to get some info out of those files: https://github.com/PhenX/php-font-lib
I was wondering if there is any way to get the font family name, by using that library or any other, because I haven't found much info about it.
As an example, let's say I have this two fonts TTF files: Roboto Light and Roboto Bold. What I want is to get "Roboto" which would be the family name of those fonts.
Cheers!
Upvotes: 1
Views: 2700
Reputation: 2287
There is a method named \FontLib\Font::getFontName
in php-font-lib that returns font family name.
$font = \FontLib\Font::load('./fonts/OpenSans-Bold.ttf');
$font->parse();
echo $font->getFontName();
// prints: Open Sans
EDIT
TTF file stores font family name inside the name
table at the ID 1 (as described here). FontLib
parses this table and returns you this value when you call getFontName()
method. In your case your ttf file contains Roboto Light
string in Font Family Name
row. I suggest you to either use this value or strip the additional font characteristics from font name.
Upvotes: 0