Skip to content

Instantly share code, notes, and snippets.

@youpy
Created August 21, 2011 16:21
Show Gist options
  • Save youpy/1160811 to your computer and use it in GitHub Desktop.
Save youpy/1160811 to your computer and use it in GitHub Desktop.
# ruby ttf_glitch.rb target.ttf > glitched.ttf
def main
filename = ARGV.shift
open(filename, 'rb') do |f|
content = f.read
offset = glyph_offset(content)
length = glyph_length(content)
head = content[0, offset]
glyphs = content[offset, length]
other = content[offset + length .. -1]
glyphs.gsub!(/\w/, '0')
print head + glyphs + other
end
end
def glyph_offset(data)
data[data.index('glyf') + 8, 4].unpack("N")[0]
end
def glyph_length(data)
data[data.index('glyf') + 12, 4].unpack("N")[0]
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment