thumb_gen 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/lib/thumb_gen/generator.rb +37 -14
- data/lib/thumb_gen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96583f8cea87b49a125c5f5d6499b9b9c1f17b4cf0876e1e69c83f4d3d842f6b
|
4
|
+
data.tar.gz: 19f73d44d5d410f5cf63c742962e9bc66231e82b56df70115bae652526c87c79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b694d60b9ebb8746f68f1e5a3604027a7b6748d7b5e758268b978f844eadfecd4b355a6625cf46c617bb1d1b4efbe325a8a18f9fef6061d700d7a9655ccd8461
|
7
|
+
data.tar.gz: 85f0e68efa2e949980550f5fa47b4605bc1a4070e06925cb680d11580d2b20e69fb68326b68a21c25414578f30ed577450847c619c58f63cfffaea576f0c686a
|
data/lib/thumb_gen/generator.rb
CHANGED
@@ -81,28 +81,51 @@ module ThumbGen
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def wrap_text(text, max_width, opts)
|
84
|
-
words = text.split(/\s+/)
|
85
|
-
lines = []
|
86
|
-
line = ''
|
87
84
|
draw = Magick::Draw.new
|
88
85
|
draw.font = opts[:font]
|
89
86
|
draw.pointsize = opts[:font_size]
|
90
87
|
draw.font_weight = opts[:font_weight]
|
91
88
|
draw.font_style = opts[:font_style]
|
92
89
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
90
|
+
if text.include?(' ')
|
91
|
+
# 📝 For languages with spaces (e.g. English) → wrap by words
|
92
|
+
words = text.split(/\s+/)
|
93
|
+
lines = []
|
94
|
+
line = ''
|
95
|
+
|
96
|
+
words.each do |word|
|
97
|
+
test_line = line.empty? ? word : "#{line} #{word}"
|
98
|
+
width = draw.get_type_metrics(background, test_line).width
|
99
|
+
if width <= max_width
|
100
|
+
line = test_line
|
101
|
+
else
|
102
|
+
lines << line unless line.empty?
|
103
|
+
line = word
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
lines << line unless line.empty?
|
108
|
+
lines.join("\n")
|
109
|
+
else
|
110
|
+
# 🇯🇵 For languages without spaces (e.g. Japanese, Chinese) → wrap by character
|
111
|
+
chars = text.scan(/.{1}/m)
|
112
|
+
lines = []
|
113
|
+
line = ''
|
114
|
+
|
115
|
+
chars.each do |char|
|
116
|
+
test_line = line + char
|
117
|
+
width = draw.get_type_metrics(background, test_line).width
|
118
|
+
if width <= max_width
|
119
|
+
line = test_line
|
120
|
+
else
|
121
|
+
lines << line unless line.empty?
|
122
|
+
line = char
|
123
|
+
end
|
101
124
|
end
|
102
|
-
end
|
103
125
|
|
104
|
-
|
105
|
-
|
126
|
+
lines << line unless line.empty?
|
127
|
+
lines.join("\n")
|
128
|
+
end
|
106
129
|
end
|
107
130
|
|
108
131
|
def text_options(text)
|
data/lib/thumb_gen/version.rb
CHANGED