Skip to content

Instantly share code, notes, and snippets.

@dtinth
Last active September 1, 2017 10:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/ee452a1451b4328634fb to your computer and use it in GitHub Desktop.
Save dtinth/ee452a1451b4328634fb to your computer and use it in GitHub Desktop.
require 'base64'
require 'erb'
title, subtitle, *text, image_number = ARGV
output_file = "image%02d.cover.png" % [image_number.to_i]
html = ERB.new(File.read('title.template.html.erb')).result(binding)
data_url = "data:text/html;base64,#{Base64.strict_encode64(html)}"
RASTERIZE = "/usr/local/share/phantomjs/examples/rasterize.js"
system "phantomjs #{RASTERIZE} '#{data_url}' '#{output_file}'"
<!DOCTYPE html><meta charset=utf-8>
<style>
body { padding: 0; margin: 0; }
#outer {
width: 1632px; height: 1224px;
color: white; background: black;
font: bold 192px/1.3 Helvetica Neue, sans-serif;
position: relative;
}
#inner {
position: absolute; top: 50%; left: 0; right: 0;
-webkit-transform: translateY(-50%);
text-align: center;
padding: 32px;
}
.title { color: #faf543; }
.subtitle { }
.text {
font-weight: normal;
font-size: 70%;
line-height: 1.15;
margin-top: 1ex;
}
</style>
</head><body>
<div id="outer">
<div id="inner">
<div class="title"><%= title %></div>
<div class="subtitle"><%= subtitle %></div>
<div class="text"><%= text.join('<br>') %></div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment