Skip to content

Instantly share code, notes, and snippets.

@kimadactyl
Last active January 15, 2019 17:47
Show Gist options
  • Save kimadactyl/8477223 to your computer and use it in GitHub Desktop.
Save kimadactyl/8477223 to your computer and use it in GitHub Desktop.
Converting a csv list into a bunch of cards for the Art of Noises boardgame.
require 'rubygems'
require 'RMagick'
require 'csv'
include Magick
$imagepath = 'images/'
cardlist = '../wordlist.csv'
# Function to create all the cards
def create_card(caption)
# Create blank image
c = Image.new(822,597)
# Create caption
t = Magick::Image.read("caption:#{caption}") {
self.font = 'Cambria-Regular'
self.stroke = 'transparent'
self.fill = 'black'
self.size = "822x597"
self.gravity = Magick::CenterGravity
}.first
# Composite image with text
c.composite!(t, 0, 0, Magick::SrcOverCompositeOp)
# Write the file, first making a nice filename
file = caption.gsub(/( )/, '_').downcase
c.write($imagepath + file + ".png")
# Log to the console
print $imagepath + file + ".png written \n"
# Destroy it or your computer grinds to a halt, oops
c.destroy!
end
# Choose the row index as appropriate for your needs
CSV.foreach(cardlist) do |row|
text = row[1]
create_card(text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment