Skip to content

Commit

Permalink
Format captain
Browse files Browse the repository at this point in the history
  • Loading branch information
emaillenin committed Jun 18, 2015
1 parent 5ac788e commit 5141e14
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
image_list.from_blob(File.open(base_image_path).read)
image_list.alpha(Magick::ActivateAlphaChannel)

output = "#{File.dirname(base_image_path)}/mojo_#{File.basename(base_image_path)}"
output = "#{File.dirname(base_image_path)}/mojo_#{Time.now.strftime('%Y%m%d')}_#{File.basename(base_image_path)}"
FileUtils::copy(base_image_path, output)


Expand Down
19 changes: 14 additions & 5 deletions src/caption_annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ class CaptionAnnotate
# TODO Auto create new lines based on word count appropriate for each line

def apply_template
canvas = Magick::Image.new(800, 600) do |c|
c.background_color = 'rgba(23,168,230,0.9)'
canvas = Magick::Image.new(700, 500) do |c|
c.background_color = 'rgba(23,168,230,0.9)' # blue
# c.background_color = 'rgba(150,93,14,0.9)' # brown
# c.background_color = 'rgba(230,150,38,0.9)' # orange
end

caption = 'Rahul Dravid will coach India A & India U-19 teams.'
# puts format_caption(caption,4)
center_caption = Draw.new
center_caption.annotate(canvas, 0, 0, 0, 0, "VIRAT KOHLI'S 169\n IS HIS HIGHEST SCORE\nIN TEST MATCHES.") do
center_caption.annotate(canvas, 0, 0, 0, 0, format_caption(caption,4, true)) do
self.gravity = Magick::CenterGravity
self.font_weight = Magick::BoldWeight
self.kerning = 1
self.pointsize = 60
self.pointsize = 50
# self.font = "whatever.ttf"
self.interline_spacing = 15
self.fill = 'white'
Expand All @@ -31,9 +35,14 @@ def apply_template
self.stroke = 'none'
end

output = '/Users/leninraj/Documents/8dict.jpg'
output = '/Users/leninraj/Downloads/8dict.png'
puts "Writing to #{output}"
canvas.write(output)
output
end

def format_caption(caption, break_at = 3, should = true)
return caption unless should
caption.split.each_slice(break_at).to_a.each_with_object([]) {|item,acc| acc << item.join(' ')}.join("\n")
end
end
6 changes: 3 additions & 3 deletions src/image_annotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def apply_template
background_caption.fill(caption['background_color'])
background_caption.stroke_opacity(0)
background_caption.rectangle(0,
0.77 * @source_image.rows,
0.8 * @source_image.rows,
@source_image.columns,
@source_image.rows)
background_caption.draw(@image_list)
Expand Down Expand Up @@ -44,8 +44,8 @@ def apply_template

def text_offset
if @caption['text'].to_s.count("\n") == 2
return 0.79
return 0.8
end
0.28
0.88
end
end
20 changes: 9 additions & 11 deletions template.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@

image:
path: /Users/leninraj/Downloads/test.jpg

image_copyright:
file: logo.png
file: logo-only-white.png
location: NorthEastGravity

hashtag:
text: ThankYouDhoni
text: india
x_offset: 25
y_offset: 25
font: Roboto
color: white

caption_player:
text: "90 MATCHES\n4,876 RUNS\n38.09 AVERAGE\n 224 HIGH SCORE\n 33 FIFTIES\n 6 HUNDREDS\n 256 CATCHES\n38 STUMPINGS"
line_spacing: 10
aption_player:
text: "2nd ODI: Australia win\nby 4 wickets"
line_spacing: 15
blur: 0.4
font: Serif
size: 80
size: 45
color: white
quote: false
background: false
background: true
# background_color: rgba(150,93,14,0.9) # brown
# background_color: rgba(255,255,255,0.8) # white
# background_color: rgba(10,10,10,0.9) # black
background_color: rgba(23,168,230,0.9) # blue
background_color: rgba(10,10,10,0.9) # black
# background_color: rgba(23,168,230,0.9) # blue
# background_color: rgba(150,14,93,0.5) # pink
background_opacity: 0.9

0 comments on commit 5141e14

Please sign in to comment.