thumb_gen 0.1.1 → 0.2.0
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/README.md +82 -19
- data/fonts/NotoSansJP-Bold.ttf +0 -0
- data/fonts/NotoSansJP-Regular.ttf +0 -0
- data/fonts/NotoSansJP-Thin.ttf +0 -0
- data/fonts/PublicSans-Bold.ttf +0 -0
- data/fonts/PublicSans-BoldItalic.ttf +0 -0
- data/fonts/PublicSans-Regular.ttf +0 -0
- data/fonts/PublicSans-Thin.ttf +0 -0
- data/fonts/PublicSans-ThinItalic.ttf +0 -0
- data/fonts/Roboto-Bold.ttf +0 -0
- data/fonts/Roboto-BoldItalic.ttf +0 -0
- data/fonts/Roboto-Italic.ttf +0 -0
- data/fonts/Roboto-Regular.ttf +0 -0
- data/fonts/Roboto-Thin.ttf +0 -0
- data/fonts/Roboto-ThinItalic.ttf +0 -0
- data/lib/thumb_gen/generator.rb +33 -32
- data/lib/thumb_gen/version.rb +1 -1
- data/sample_output.jpg +0 -0
- metadata +17 -7
- data/default.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0664e5568eaee147154ba653f077ce91355e19f6bb065ee0881180a02c0f76c
|
4
|
+
data.tar.gz: e5b39c3c08552118d2ca6fffd88f9b52ca7a5653ab10bd757ae2a9e9abd32567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 892af539b3de549434c96d746b5ffdb8b1eb06941fd88cd3a6b3b19af9f60752fda995b671fba0687c63e2d90ae90b408cf2f2114201926691cd890fe20de256
|
7
|
+
data.tar.gz: 2e0231126935da9276ac0963ef9f255f7923d981c70680200ed69333b632a1f00c42861dadd29aa94b112227558d8f9f5ba3971ccf36194c26b5ec568b38a9e6
|
data/README.md
CHANGED
@@ -1,41 +1,50 @@
|
|
1
1
|
# ThumbGen
|
2
2
|
|
3
|
-
Welcome to ThumbGen, a powerful Ruby gem designed to
|
3
|
+
Welcome to ThumbGen, a powerful Ruby gem designed to generate images with customized text overlays.
|
4
|
+
Perfect for automating thumbnail creation, blog banners, and promotional images.
|
4
5
|
|
6
|
+
---
|
7
|
+
|
8
|
+
## 🖼️ Example
|
5
9
|
|
6
10
|
Input Image | Output Image
|
7
11
|
:-------------------------:|:-------------------------:
|
8
|
-

|
12
|
+
 | 
|
9
13
|
|
14
|
+
---
|
10
15
|
|
11
|
-
## Installation
|
16
|
+
## 💎 Installation
|
12
17
|
|
13
|
-
|
18
|
+
Add to your Gemfile:
|
14
19
|
|
15
20
|
```bash
|
16
21
|
bundle add thumb_gen
|
17
22
|
```
|
18
23
|
|
19
|
-
|
20
|
-
|
24
|
+
Or install manually:
|
21
25
|
|
22
26
|
```bash
|
23
27
|
gem install thumb_gen
|
24
28
|
```
|
25
29
|
|
26
|
-
|
30
|
+
---
|
27
31
|
|
28
|
-
|
32
|
+
## ✨ Usage
|
33
|
+
|
34
|
+
You can generate an image by providing background, output path, and an array of text overlays:
|
29
35
|
|
30
36
|
```ruby
|
37
|
+
require 'thumb_gen'
|
38
|
+
|
31
39
|
output_path = 'sample_output.jpg'
|
32
40
|
background_url = 'sample_input.jpg'
|
41
|
+
|
33
42
|
texts = [
|
34
43
|
{
|
35
44
|
text: 'ThumbGen is a Ruby gem that simplifies the creation of article thumbnails',
|
36
45
|
wrapped_width: 800,
|
46
|
+
font: 'PublicSans-Bold',
|
37
47
|
font_size: 80,
|
38
|
-
style: 'bold',
|
39
48
|
color: '#047857',
|
40
49
|
outline_color: '#f8fafc',
|
41
50
|
outline_width: 1,
|
@@ -46,8 +55,8 @@ texts = [
|
|
46
55
|
{
|
47
56
|
text: '5 min read',
|
48
57
|
wrapped_width: 800,
|
58
|
+
font: 'Roboto-Italic',
|
49
59
|
font_size: 48,
|
50
|
-
style: 'italic',
|
51
60
|
color: '#09090b',
|
52
61
|
gravity: 'southwest',
|
53
62
|
position_x: 400,
|
@@ -56,34 +65,88 @@ texts = [
|
|
56
65
|
{
|
57
66
|
text: 'My Blog',
|
58
67
|
wrapped_width: 1280,
|
68
|
+
font: 'Roboto-BoldItalic',
|
59
69
|
font_size: 64,
|
60
|
-
style: 'bold-and-italic',
|
61
70
|
color: '#86198f',
|
62
71
|
gravity: 'northeast',
|
63
72
|
position_x: 200,
|
64
73
|
position_y: 30
|
65
74
|
}
|
66
75
|
]
|
76
|
+
|
67
77
|
options = {
|
68
78
|
width: 1280,
|
69
79
|
height: 720,
|
70
80
|
format: 'jpg'
|
71
81
|
}
|
72
82
|
|
73
|
-
# Generate the image
|
74
83
|
ThumbGen.generate(output_path, background_url, texts, options)
|
75
84
|
```
|
76
85
|
|
77
|
-
|
86
|
+
> Font files like `Roboto-BoldItalic.ttf` are bundled in the gem’s `fonts/` folder.
|
87
|
+
Use only the filename **without extension** as the `font:` value.
|
88
|
+
|
89
|
+
- NotoSansJP-Regular
|
90
|
+
- NotoSansJP-Bold
|
91
|
+
- NotoSansJP-Thin
|
92
|
+
- PublicSans-Regular
|
93
|
+
- PublicSans-Bold
|
94
|
+
- PublicSans-BoldItalic
|
95
|
+
- PublicSans-Thin
|
96
|
+
- PublicSans-ThinItalic
|
97
|
+
- Roboto-Regular
|
98
|
+
- Roboto-Bold
|
99
|
+
- Roboto-BoldItalic
|
100
|
+
- Roboto-Italic
|
101
|
+
- Roboto-Thin
|
102
|
+
- Roboto-ThinItalic
|
103
|
+
|
104
|
+
---
|
105
|
+
|
106
|
+
## 🛠 Development
|
107
|
+
|
108
|
+
After cloning the repo, install dependencies:
|
109
|
+
|
110
|
+
```bash
|
111
|
+
bin/setup
|
112
|
+
```
|
113
|
+
|
114
|
+
Run tests:
|
115
|
+
|
116
|
+
```bash
|
117
|
+
rake spec
|
118
|
+
```
|
119
|
+
|
120
|
+
Try it in IRB:
|
121
|
+
|
122
|
+
```bash
|
123
|
+
bin/console
|
124
|
+
```
|
125
|
+
|
126
|
+
To install the gem locally:
|
127
|
+
|
128
|
+
```bash
|
129
|
+
bundle exec rake install
|
130
|
+
```
|
131
|
+
|
132
|
+
To release a new version:
|
133
|
+
|
134
|
+
1. Update the version in `lib/thumb_gen/version.rb`
|
135
|
+
2. Run:
|
136
|
+
|
137
|
+
```bash
|
138
|
+
bundle exec rake release
|
139
|
+
```
|
78
140
|
|
79
|
-
|
141
|
+
---
|
80
142
|
|
81
|
-
|
143
|
+
## 🤝 Contributing
|
82
144
|
|
83
|
-
|
145
|
+
Bug reports and pull requests are welcome at:
|
146
|
+
[https://github.com/YutoYasunaga/thumb_gen](https://github.com/YutoYasunaga/thumb_gen)
|
84
147
|
|
85
|
-
|
148
|
+
---
|
86
149
|
|
87
|
-
## License
|
150
|
+
## 📄 License
|
88
151
|
|
89
|
-
|
152
|
+
Released under the [MIT License](https://opensource.org/licenses/MIT)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/thumb_gen/generator.rb
CHANGED
@@ -38,52 +38,53 @@ module ThumbGen
|
|
38
38
|
# Adds text overlays to the image based on provided text configurations.
|
39
39
|
def add_texts
|
40
40
|
texts.each do |text|
|
41
|
-
draw_text(
|
42
|
-
background,
|
43
|
-
text[:text],
|
44
|
-
wrapped_width: wrapped_width(text[:wrapped_width]),
|
45
|
-
font: font(text[:style]),
|
46
|
-
font_size: text[:font_size] || 64,
|
47
|
-
font_weight: font_weight(text[:style]),
|
48
|
-
font_style: font_style(text[:style]),
|
49
|
-
color: text[:color] || '#000000',
|
50
|
-
outline_color: text[:outline_color],
|
51
|
-
outline_width: text[:outline_width] || 0,
|
52
|
-
gravity: gravity(text[:gravity]),
|
53
|
-
position_x: text[:position_x] || 0,
|
54
|
-
position_y: text[:position_y] || 0
|
55
|
-
)
|
41
|
+
draw_text(background, text[:text], **text_options(text))
|
56
42
|
end
|
57
43
|
end
|
58
44
|
|
45
|
+
def text_options(text)
|
46
|
+
font_family = text[:font] || 'PUblisSans-Regular'
|
47
|
+
{
|
48
|
+
wrapped_width: wrapped_width(text[:wrapped_width]),
|
49
|
+
font: font(font_family),
|
50
|
+
font_size: text[:font_size] || 64,
|
51
|
+
font_weight: font_weight(font_family),
|
52
|
+
font_style: font_style(font_family),
|
53
|
+
color: text[:color] || '#000000',
|
54
|
+
outline_color: text[:outline_color],
|
55
|
+
outline_width: text[:outline_width] || 0,
|
56
|
+
gravity: gravity(text[:gravity]),
|
57
|
+
position_x: text[:position_x] || 0,
|
58
|
+
position_y: text[:position_y] || 0
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
59
62
|
# Determines the width within which text should be wrapped.
|
60
63
|
def wrapped_width(width)
|
61
64
|
width || background.columns
|
62
65
|
end
|
63
66
|
|
64
67
|
# Determines the font based on the style.
|
65
|
-
def font(
|
66
|
-
|
67
|
-
|
68
|
-
when 'italic' then 'Arial-Italic'
|
69
|
-
when 'bold-and-italic' then 'Arial-Bold-Italic'
|
70
|
-
else 'Arial'
|
71
|
-
end
|
68
|
+
def font(font_family)
|
69
|
+
base = File.expand_path('../../fonts', __dir__)
|
70
|
+
File.join(base, "#{font_family}.ttf")
|
72
71
|
end
|
73
72
|
|
74
|
-
# Determines the font weight based on the
|
75
|
-
def font_weight(
|
76
|
-
|
77
|
-
|
78
|
-
else
|
73
|
+
# Determines the font weight based on the name.
|
74
|
+
def font_weight(font_family)
|
75
|
+
if font_family.downcase.include?('bold')
|
76
|
+
Magick::BolderWeight
|
77
|
+
else
|
78
|
+
Magick::NormalWeight
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
# Determines the font style based on the
|
83
|
-
def font_style(
|
84
|
-
|
85
|
-
|
86
|
-
else
|
82
|
+
# Determines the font style based on the name.
|
83
|
+
def font_style(font_family)
|
84
|
+
if font_family.downcase.include?('italic')
|
85
|
+
Magick::ItalicStyle
|
86
|
+
else
|
87
|
+
Magick::NormalStyle
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
data/lib/thumb_gen/version.rb
CHANGED
data/sample_output.jpg
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thumb_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YutoYasunaga
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rmagick
|
@@ -39,7 +38,20 @@ files:
|
|
39
38
|
- LICENSE.txt
|
40
39
|
- README.md
|
41
40
|
- Rakefile
|
42
|
-
-
|
41
|
+
- fonts/NotoSansJP-Bold.ttf
|
42
|
+
- fonts/NotoSansJP-Regular.ttf
|
43
|
+
- fonts/NotoSansJP-Thin.ttf
|
44
|
+
- fonts/PublicSans-Bold.ttf
|
45
|
+
- fonts/PublicSans-BoldItalic.ttf
|
46
|
+
- fonts/PublicSans-Regular.ttf
|
47
|
+
- fonts/PublicSans-Thin.ttf
|
48
|
+
- fonts/PublicSans-ThinItalic.ttf
|
49
|
+
- fonts/Roboto-Bold.ttf
|
50
|
+
- fonts/Roboto-BoldItalic.ttf
|
51
|
+
- fonts/Roboto-Italic.ttf
|
52
|
+
- fonts/Roboto-Regular.ttf
|
53
|
+
- fonts/Roboto-Thin.ttf
|
54
|
+
- fonts/Roboto-ThinItalic.ttf
|
43
55
|
- lib/thumb_gen.rb
|
44
56
|
- lib/thumb_gen/generator.rb
|
45
57
|
- lib/thumb_gen/utils.rb
|
@@ -54,7 +66,6 @@ metadata:
|
|
54
66
|
allowed_push_host: https://rubygems.org
|
55
67
|
homepage_uri: https://github.com/YutoYasunaga/thumb_gen
|
56
68
|
source_code_uri: https://github.com/YutoYasunaga/thumb_gen.git
|
57
|
-
post_install_message:
|
58
69
|
rdoc_options: []
|
59
70
|
require_paths:
|
60
71
|
- lib
|
@@ -69,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
80
|
- !ruby/object:Gem::Version
|
70
81
|
version: '0'
|
71
82
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
83
|
+
rubygems_version: 3.6.7
|
74
84
|
specification_version: 4
|
75
85
|
summary: Auto generate customized thumbnails for articles.
|
76
86
|
test_files: []
|
data/default.png
DELETED
Binary file
|