Skip to content

Instantly share code, notes, and snippets.

@vipulasri
Created June 21, 2021 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vipulasri/bb75619f79133727804fa1afff0eb517 to your computer and use it in GitHub Desktop.
Save vipulasri/bb75619f79133727804fa1afff0eb517 to your computer and use it in GitHub Desktop.
Extract images from font
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