Skip to content

Instantly share code, notes, and snippets.

@Demonstrandum
Last active February 4, 2018 23:05
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 Demonstrandum/dcd4b2027205296adb9f89ff65546296 to your computer and use it in GitHub Desktop.
Save Demonstrandum/dcd4b2027205296adb9f89ff65546296 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rmagick'
include Magick
PRONOUN_DIR = File.expand_path './pronoun_images/'
def parse_pronouns file
raw = File.read File.expand_path file
raw.split("\n").map{ |line| line.split(/--|\//).map(&:strip) }
end
parse_pronouns('pronouns.txt').flatten.each do |pronoun|
size = [pronoun.size * 12, 32]
image = text = nil
text_width = size[0]
until size[0] > text_width.ceil + 15
image = Image.new(*size) { |prop| prop.background_color = 'transparent' }
text = Draw.new
image.annotate text, *size, 0, 0, pronoun do
text.gravity = NorthGravity
text.pointsize = size.last - 5
text.fill = '#789823'
text.font_family = 'Arial'
end
text_width = text.get_multiline_type_metrics(image, pronoun).width
size[0] += 15
end
image.format = 'png'
Dir.mkdir PRONOUN_DIR unless File.exists? PRONOUN_DIR
image.write "#{PRONOUN_DIR}/#{pronoun.delete ">"}.png"
end
>I -- >me -- >my/>mine
>you -- >you -- >your/>yours
>thou -- >thee -- >thy/>thine
>he -- >him -- >his
>she -- >her -- >hers
>it -- >it -- >its
>we -- >us -- >our/>ours
>they -- >them -- >their/>theirs
>m'lady -- >m'lady -- >m'lady's
self -- selves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment