Created
February 2, 2014 09:28
-
-
Save jhawthorn/8765268 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tempfile' | |
module Colbert | |
extend self | |
def generate_image file_path, text | |
on_notice = text.map(&:upcase) | |
text_width=350*1 | |
text_height=50*1 | |
input_coords = %W[ | |
0,0 | |
#{text_width},0 | |
#{text_width},#{text_height} | |
0,#{text_height} | |
] | |
dest_coords = [ | |
"212,1 522,37 520,82 213,53", | |
"213,65 520,95 520,139 214,116", | |
"215,134 519,157 518,198 215,181", | |
"215,198 519,214 518,256 215,245", | |
"215,262 517,272 517,316 215,309", | |
"221,326 523,329 522,372 221,374", | |
"214,391 516,388 516,431 215,438", | |
"215,455 515,447 514,487 214,501", | |
"213,520 516,505 515,551 213,566", | |
"220,585 520,561 521,602 220,630" | |
].map do |s| | |
s.split(' ') | |
end | |
command = %W[convert colbert.jpg -virtual-pixel transparent] | |
dest_coords.each_with_index do |dest, i| | |
text = on_notice[i] | |
pairs = input_coords.zip(dest) | |
command << "(" | |
command.concat %W[-background transparent -fill white -font OpenSans-CondBold.ttf -strokewidth 2 -stroke black -size 350x50 -gravity center] | |
command << "label:#{text}" | |
command.concat %W[+distort Perspective #{pairs.flatten.join(' ')}] | |
command << ')' | |
end | |
command.concat %W[-layers merge] | |
command << file_path | |
p command | |
system *command | |
end | |
end | |
on_notice = [ | |
'Distractions', | |
'You Know Who You Are', | |
'The Weather Channel', | |
'Black Hole at Center of Galaxy', | |
'Fantasies of Jane Fonda', | |
'Grizzly Bears', | |
'Candy Apples', | |
'Mike Huckabee', | |
'Pant Cuffs', | |
'OK GO' | |
] | |
Colbert.generate_image('output.png', on_notice) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment