Created
June 21, 2021 06:27
-
-
Save vipulasri/bb75619f79133727804fa1afff0eb517 to your computer and use it in GitHub Desktop.
Extract images from font
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
require 'ttfunk' | |
file = TTFunk::File.open(ARGV[0]) | |
size = 200 | |
output_dir = ARGV[2] | |
`mkdir #{output_dir}` | |
cmap = file.cmap | |
chars = {} | |
unicode_chars = [] | |
cmap.tables.each do |subtable| | |
next if !subtable.unicode? | |
chars = chars.merge( subtable.code_map ) | |
end | |
chars = chars.keys | |
puts "\n -- Found #{chars.length} characters in this font \n\n" | |
chars.each do |t| | |
`magick convert -size #{size} -background 'transparent' -fill '#fff' -gravity Center -font #{ARGV[0]} label:\"#{t.chr('UTF-8')}\" ./#{output_dir}/#{t}.png` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment