meme_captain 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +6 -0
- data/lib/meme_captain/meme.rb +39 -12
- data/lib/meme_captain/version.rb +1 -1
- metadata +5 -4
data/ChangeLog
ADDED
data/lib/meme_captain/meme.rb
CHANGED
|
@@ -5,7 +5,19 @@ module MemeCaptain
|
|
|
5
5
|
module_function
|
|
6
6
|
|
|
7
7
|
# Create a meme image.
|
|
8
|
+
#
|
|
8
9
|
# Input can be an IO object or a blob of data.
|
|
10
|
+
#
|
|
11
|
+
# Options:
|
|
12
|
+
# max_lines - maximum number of text lines per caption
|
|
13
|
+
# min_pointsize - minimum point size
|
|
14
|
+
# super_sample - work this many times larger before shrinking
|
|
15
|
+
# text_height_pct - float percentage of image height for each caption
|
|
16
|
+
# text_width_pct - float percentage of image width for each caption
|
|
17
|
+
#
|
|
18
|
+
# Any other options will be set on the Draw objects for the text and
|
|
19
|
+
# can be used to control text fill, stroke, etc. See RMagick annotate
|
|
20
|
+
# attributes.
|
|
9
21
|
def meme(input, top_text, bottom_text, options={})
|
|
10
22
|
img = Magick::ImageList.new
|
|
11
23
|
if input.respond_to?(:read)
|
|
@@ -14,23 +26,39 @@ module MemeCaptain
|
|
|
14
26
|
img.from_blob(input)
|
|
15
27
|
end
|
|
16
28
|
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
options = {
|
|
30
|
+
:max_lines => 16,
|
|
31
|
+
:min_pointsize => 12,
|
|
32
|
+
:super_sample => 2.0,
|
|
33
|
+
:text_height_pct => 0.25,
|
|
34
|
+
:text_width_pct => 0.9,
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
# Draw options
|
|
37
|
+
:fill => 'white',
|
|
38
|
+
:font => 'Impact',
|
|
39
|
+
:stroke => 'black',
|
|
40
|
+
:stroke_width => 8,
|
|
41
|
+
}.merge(options)
|
|
42
|
+
|
|
43
|
+
max_lines = options.delete(:max_lines)
|
|
44
|
+
super_sample = options.delete(:super_sample)
|
|
45
|
+
min_pointsize = options.delete(:min_pointsize) * super_sample
|
|
46
|
+
|
|
47
|
+
text_width = img.page.width * options.delete(:text_width_pct) * super_sample
|
|
48
|
+
text_height = img.page.height * options.delete(:text_height_pct) *
|
|
49
|
+
super_sample
|
|
23
50
|
|
|
24
51
|
text_layer = Magick::Image.new(
|
|
25
52
|
img.page.width * super_sample, img.page.height * super_sample) {
|
|
26
53
|
self.background_color = 'none'
|
|
27
|
-
self.density =
|
|
54
|
+
self.density = 72.0 * super_sample
|
|
28
55
|
}
|
|
29
56
|
|
|
30
|
-
draw = Magick::Draw.new
|
|
57
|
+
draw = Magick::Draw.new {
|
|
58
|
+
options.each { |k,v| self.send("#{k}=", v) }
|
|
59
|
+
}
|
|
31
60
|
|
|
32
|
-
draw.
|
|
33
|
-
draw.font = 'Impact'
|
|
61
|
+
draw.extend(Draw)
|
|
34
62
|
|
|
35
63
|
[
|
|
36
64
|
[Caption.new(top_text), Magick::NorthGravity],
|
|
@@ -52,15 +80,14 @@ module MemeCaptain
|
|
|
52
80
|
draw.gravity = gravity
|
|
53
81
|
draw.pointsize = choice.pointsize
|
|
54
82
|
|
|
55
|
-
draw.stroke =
|
|
56
|
-
draw.stroke_width = 8
|
|
83
|
+
draw.stroke = options[:stroke]
|
|
57
84
|
draw.annotate text_layer, 0, 0, 0, 0, choice.text
|
|
58
85
|
|
|
59
86
|
draw.stroke = 'none'
|
|
60
87
|
draw.annotate text_layer, 0, 0, 0, 0, choice.text
|
|
61
88
|
end
|
|
62
89
|
|
|
63
|
-
text_layer.resize!(1 / super_sample)
|
|
90
|
+
text_layer.resize!(1.0 / super_sample)
|
|
64
91
|
|
|
65
92
|
img.each do |frame|
|
|
66
93
|
frame.composite!(text_layer, -frame.page.x, -frame.page.y,
|
data/lib/meme_captain/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: meme_captain
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 15
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 8
|
|
10
|
+
version: 0.0.8
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Matthew M. Boedicker
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-11-
|
|
18
|
+
date: 2011-11-23 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -114,6 +114,7 @@ extra_rdoc_files: []
|
|
|
114
114
|
files:
|
|
115
115
|
- .gitignore
|
|
116
116
|
- COPYING
|
|
117
|
+
- ChangeLog
|
|
117
118
|
- README.md
|
|
118
119
|
- config.ru
|
|
119
120
|
- img_cache/source/.gitignore
|