Created
January 29, 2025 15:16
-
-
Save Fizzyhex/098e570f8bef474ad7ad86b19b3887a9 to your computer and use it in GitHub Desktop.
Python utility for renaming ttf font files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ############################################## | |
| # Source: https://superuser.com/questions/120593/how-do-you-change-a-ttf-font-name | |
| # Requires fonttools: pip install fonttools | |
| # | |
| # Usage: rename_font.py <input_path> <output_path> <new_name> | |
| # Example: rename_font.py Tahoma.ttf Tahoma7.ttf "Tahoma7" | |
| ############################################## | |
| from fontTools.ttLib import TTFont | |
| import sys | |
| def rename_font(input_path, output_path, new_name): | |
| font = TTFont(input_path) | |
| for record in font['name'].names: | |
| if record.nameID in [1, 4, 6]: # Family name, Full name, PostScript name | |
| record.string = new_name.encode(record.getEncoding()) | |
| font.save(output_path) | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 4: | |
| print("Usage: rename_font.py <input_path> <output_path> <new_name>") | |
| print("Example: rename_font.py Tahoma.ttf Tahoma7.ttf \"Tahoma7\"") | |
| sys.exit(1) | |
| rename_font(sys.argv[1], sys.argv[2], sys.argv[3]) | |
| print("Renamed font successfully!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment