-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_album_art.rb
73 lines (64 loc) · 2.22 KB
/
generate_album_art.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'json'
require 'date'
require './setlists'
require './create_dir_tree'
require 'rmagick'
include Magick
data_dir = 'data'
output_dir = 'out'
# create the data dirs to hold the generated art
create_dir_tree(output_dir)
def generate(fnames)
fnames = [
'04-03-70.jpg', '19700403_0396.jpg'
]
target_cols = 500 # how wide we want the final image
target_rows = 425 # how much space to leave at the bottom
fnames.each do |file|
puts file
img = Image.read(file).first
if img.columns < target_cols || img.rows < target_rows # not perfect; small images will crop horizontally
puts "too small"
next
end
# keep the image aspect, but make it as tall as the image area
img.change_geometry!("x#{target_rows}") { |cols, rows, i|
puts cols, rows
i.resize!(cols, rows)
}
# create a new white image and overlay the image from above
white_bg = Image.new(target_cols, target_cols) { |options| options.background_color = 'white' }
target = white_bg.composite(img, NorthGravity, OverCompositeOp)
# annotate with text
text = Draw.new
text.pointsize = 20
text.font = '/Users/jjulian/Library/Fonts/ChewedPenBB.otf'
text.gravity = WestGravity
text.fill = '#151B54' # ballpoint pen blue
text_row = 202
x_margin = 10
text_height = 24
text.annotate(target, 0, 0, x_margin, text_row, "Armory Fieldhouse, University of Cincinnati, Cincinnati, OH")
text.annotate(target, 0, 0, x_margin, text_row + text_height, "April 3, 1970")
target.write("final-#{file}")
end
end
# generate album art for search results
setlists = Setlists.new
setlists.each do |show|
date = Date.strptime(show.eventDate, '%d-%m-%Y')
catalog_date = "#{date.year}-#{'%02d' % date.month}-#{'%02d' % date.day}"
if date.year == 1975
full_data_dir = "#{data_dir}/#{date.year}/#{catalog_date}"
Dir.children(full_data_dir).each do |file|
puts catalog_date, file
json_results = JSON.parse(File.read("#{full_data_dir}/#{file}"))
json_results["images_results"].each do |image|
if image["source"] =~ /grateful|dead|jerrygarcia|liveforlivemusic|flickr/
puts image["original"]
# TODO generate album art
end
end
end
end
end