Permalink
Browse files

Cleanup. Include Impact font

  • Loading branch information...
1 parent 23acfdb commit dac8a72de7b2bef02ea0e63f4deafe198449fb21 @cmdrkeene committed May 7, 2011
View
@@ -2,3 +2,37 @@
An RMagick-based two-caption meme generator.
+![Profit](example.jpg)
+
+## Install
+
+You'll need [ImageMagick](http://www.imagemagick.org/script/index.php) installed.
+The easiest way is to use [Homebrew](https://github.com/mxcl/homebrew).
+
+ brew install imagemagick
+
+## Usage
+
+To see a list of available generators:
+
+ $ memegen --list
+ a_dog
+ p_obama
+ ...
+
+To generate an image:
+
+ $ memegen a_dog "Eat Crayons" "Poop Rainbows"
+ /tmp/meme-1304797373.jpg
+ $
+
+You only have to supply one piece of text:
+
+ $ memegen a_dog "" "AWESOME"
+ /tmp/meme-1304797375.jpg
+ $
+
+## Contribute
+
+Feel free to improve this and add your own generator images!
+
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Binary file not shown.
File renamed without changes
File renamed without changes
View
@@ -2,7 +2,7 @@
require "RMagick"
class MemeGenerator
- IMPACT_PATH = "/Library/Fonts/Impact.ttf" # If you don't have OS X, fork me :)
+ IMPACT_PATH = "fonts/Impact.ttf" # If you don't have OS X, fork me :)
class << self
def run(argv = ARGV)
@@ -11,7 +11,7 @@ def run(argv = ARGV)
return list_generators if generator == "--list"
return usage unless generator && (top || bottom)
- if path = Dir.glob("images/#{generator}*").first
+ if path = Dir.glob("generators/#{generator}*").first
generate(path, top, bottom)
exit 0
else
@@ -23,12 +23,12 @@ def run(argv = ARGV)
private
def usage
- puts 'usage: memegen <nae> <top> <bottom> [--list]'
+ puts 'usage: memegen <generator> <top text> <bottom text> [--list]'
exit 1
end
def list_generators
- Dir.glob("images/*").sort.each do |path|
+ Dir.glob("generators/*").sort.each do |path|
puts File.basename(path).gsub(/\..*/, '')
end
exit 0
@@ -46,37 +46,41 @@ def generate(path, top, bottom)
draw.font_weight = Magick::BoldWeight
pointsize = image.columns / 5.0
- stroke_width = pointsize / 25.0
+ stroke_width = pointsize / 30.0
x_position = image.columns / 2
y_position = image.rows * 0.15
# Draw top
- scale, text = scale_text(top)
- bottom_draw = draw.dup
- bottom_draw.annotate(canvas, 0, 0, 0, 0, text) do
- self.interline_spacing = -(pointsize / 5)
- self.stroke_antialias(true)
- self.stroke = "black"
- self.fill = "white"
- self.gravity = Magick::NorthGravity
- self.stroke_width = stroke_width * scale
- self.pointsize = pointsize * scale
+ unless top.empty?
+ scale, text = scale_text(top)
+ bottom_draw = draw.dup
+ bottom_draw.annotate(canvas, 0, 0, 0, 0, text) do
+ self.interline_spacing = -(pointsize / 5)
+ self.stroke_antialias(true)
+ self.stroke = "black"
+ self.fill = "white"
+ self.gravity = Magick::NorthGravity
+ self.stroke_width = stroke_width * scale
+ self.pointsize = pointsize * scale
+ end
end
# Draw bottom
- scale, text = scale_text(bottom)
- bottom_draw = draw.dup
- bottom_draw.annotate(canvas, 0, 0, 0, 0, text) do
- self.interline_spacing = -(pointsize / 5)
- self.stroke_antialias(true)
- self.stroke = "black"
- self.fill = "white"
- self.gravity = Magick::SouthGravity
- self.stroke_width = stroke_width * scale
- self.pointsize = pointsize * scale
+ unless bottom.empty?
+ scale, text = scale_text(bottom)
+ bottom_draw = draw.dup
+ bottom_draw.annotate(canvas, 0, 0, 0, 0, text) do
+ self.interline_spacing = -(pointsize / 5)
+ self.stroke_antialias(true)
+ self.stroke = "black"
+ self.fill = "white"
+ self.gravity = Magick::SouthGravity
+ self.stroke_width = stroke_width * scale
+ self.pointsize = pointsize * scale
+ end
end
- output_path = "tmp/meme.jpeg"
+ output_path = "/tmp/meme-#{Time.now.to_i}.jpeg"
canvas.write(output_path)
puts output_path
exit 0
View
No changes.

0 comments on commit dac8a72

Please sign in to comment.