thumb_gen 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d4a6f7985e73484a38bca3f7e91c25f283e99144f31481f0b42bbac46e2f5158
4
- data.tar.gz: e30b3bedba0423a6adb5288b48149232a07f9d1272bf526f0a39a5bd9d34b1eb
3
+ metadata.gz: c3afc45cc8b694142b79f2cb82e3c03ec4e871894c218bede07a9c28f53fba77
4
+ data.tar.gz: 405767838d151c46427641ff2a5fa4264fa21ceec2cdf48327c2290fe9f7e24c
5
5
  SHA512:
6
- metadata.gz: 401b2124f04d5852637b53e356cae18b3362ce0c9e5ad3f1a4c8d887669b511adce4f8007eec9cdb5486e0cb593066c4bb5814a9f5eb250995b31e9c20db7459
7
- data.tar.gz: 242eb622589b8c449c0e1e33e429e7357b320bcc61df207e5b4a1516ae4e6e5437de735c0c72a2c0ceab38090d93313f117e329bc4431ed433dcccbebd7d5e31
6
+ metadata.gz: b72ee8d31e58373006a83097ae077a59af16bf5bd50740fefa353791768f1beef4f927b1ba2fe0ace9e85daa6f0e6b71c687e117c8c872a612cd7292665f0dac
7
+ data.tar.gz: '0814c2366fdba305f9bb14c66019baeca5e40bd7950990526525be48b0b744887c17645eddd19e612aeddb0d2ffc6485b5560394e13d8214ba3e08a4db21a358'
data/README.md CHANGED
@@ -1,41 +1,50 @@
1
1
  # ThumbGen
2
2
 
3
- Welcome to ThumbGen, a powerful Ruby gem designed to facilitate the dynamic generation of images with customized text overlays. This tool leverages RMagick to provide robust image manipulation capabilities, making it ideal for applications needing automated graphic content creation, such as generating thumbnails, promotional banners, or personalized images.
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
- ![Input](sample_input.jpg) | ![Output](sample_output.jpg)
12
+ ![Input](sample_input.jpg) | ![Output](sample_output.jpg)
9
13
 
14
+ ---
10
15
 
11
- ## Installation
16
+ ## 💎 Installation
12
17
 
13
- To install ThumbGen, simply add it to your application's Gemfile:
18
+ Add to your Gemfile:
14
19
 
15
20
  ```bash
16
21
  bundle add thumb_gen
17
22
  ```
18
23
 
19
- Alternatively, you can install it yourself as:
20
-
24
+ Or install manually:
21
25
 
22
26
  ```bash
23
27
  gem install thumb_gen
24
28
  ```
25
29
 
26
- ## Usage
30
+ ---
27
31
 
28
- ThumbGen is easy to use with an intuitive API. Here's a basic example of how to generate an image with text overlays:
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,97 @@ 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
- ## Development
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
+ - PublicSans-Regular
90
+ - PublicSans-Bold
91
+ - PublicSans-BoldItalic
92
+ - PublicSans-Thin
93
+ - PublicSans-ThinItalic
94
+ - Roboto-Regular
95
+ - Roboto-Bold
96
+ - Roboto-BoldItalic
97
+ - Roboto-Italic
98
+ - Roboto-Thin
99
+ - Roboto-ThinItalic
100
+ - For Japanese:
101
+ - NotoSansJP-Regular
102
+ - NotoSansJP-Bold
103
+ - NotoSansJP-Thin
104
+ - For Korean:
105
+ - NotoSansKR-Regular
106
+ - NotoSansKR-Bold
107
+ - NotoSansKR-Thin
108
+ - For Simplified Chinese
109
+ - NotoSansSC-Regular
110
+ - NotoSansSC-Bold
111
+ - NotoSansSC-Thin
112
+
113
+ ---
114
+
115
+ ## 🛠 Development
116
+
117
+ After cloning the repo, install dependencies:
118
+
119
+ ```bash
120
+ bin/setup
121
+ ```
122
+
123
+ Run tests:
124
+
125
+ ```bash
126
+ rake spec
127
+ ```
128
+
129
+ Try it in IRB:
130
+
131
+ ```bash
132
+ bin/console
133
+ ```
134
+
135
+ To install the gem locally:
136
+
137
+ ```bash
138
+ bundle exec rake install
139
+ ```
140
+
141
+ To release a new version:
142
+
143
+ 1. Update the version in `lib/thumb_gen/version.rb`
144
+ 2. Run:
145
+
146
+ ```bash
147
+ bundle exec rake release
148
+ ```
78
149
 
79
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
150
+ ---
80
151
 
81
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
152
+ ## 🤝 Contributing
82
153
 
83
- ## Contributing
154
+ Bug reports and pull requests are welcome at:
155
+ [https://github.com/YutoYasunaga/thumb_gen](https://github.com/YutoYasunaga/thumb_gen)
84
156
 
85
- Bug reports and pull requests are welcome on GitHub at https://github.com/YutoYasunaga/thumb_gen.
157
+ ---
86
158
 
87
- ## License
159
+ ## 📄 License
88
160
 
89
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
161
+ 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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -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(style)
66
- case style
67
- when 'bold' then 'Arial-Bold'
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 style.
75
- def font_weight(style)
76
- case style
77
- when 'bold', 'bold-and-italic' then Magick::BolderWeight
78
- else Magick::NormalWeight
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 style.
83
- def font_style(style)
84
- case style
85
- when 'italic', 'bold-and-italic' then Magick::ItalicStyle
86
- else Magick::NormalStyle
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
 
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thumb_gen/generator'
4
+
5
+ module ThumbGen
6
+ # rubocop:disable all
7
+ module Test
8
+ def self.generate_sample
9
+ output_path = 'sample_output.jpg'
10
+ background_url = 'sample_input.jpg'
11
+ texts = [
12
+ {
13
+ text: 'ThumbGen is a Ruby gem that simplifies the creation of article thumbnails',
14
+ wrapped_width: 800,
15
+ font: 'PublicSans-Bold',
16
+ font_size: 80,
17
+ color: '#047857',
18
+ outline_color: '#f8fafc',
19
+ outline_width: 1,
20
+ gravity: 'northwest',
21
+ position_x: 40,
22
+ position_y: 120
23
+ },
24
+ {
25
+ text: '5 min read',
26
+ wrapped_width: 800,
27
+ font: 'Roboto-Italic',
28
+ font_size: 48,
29
+ color: '#09090b',
30
+ gravity: 'southwest',
31
+ position_x: 400,
32
+ position_y: 40
33
+ },
34
+ {
35
+ text: 'My Blog',
36
+ wrapped_width: 1280,
37
+ font: 'Roboto-BoldItalic',
38
+ font_size: 64,
39
+ color: '#86198f',
40
+ gravity: 'northeast',
41
+ position_x: 200,
42
+ position_y: 30
43
+ }
44
+ ]
45
+ options = {
46
+ width: 1280,
47
+ height: 720,
48
+ format: 'jpg'
49
+ }
50
+ ThumbGen::Generator.new(output_path, background_url, texts, options).generate
51
+ end
52
+ end
53
+ # rubocop:enable all
54
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ThumbGen
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.1'
5
5
  end
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.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YutoYasunaga
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-09-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rmagick
@@ -39,9 +38,29 @@ files:
39
38
  - LICENSE.txt
40
39
  - README.md
41
40
  - Rakefile
42
- - default.png
41
+ - fonts/NotoSansJP-Bold.ttf
42
+ - fonts/NotoSansJP-Regular.ttf
43
+ - fonts/NotoSansJP-Thin.ttf
44
+ - fonts/NotoSansKR-Bold.ttf
45
+ - fonts/NotoSansKR-Regular.ttf
46
+ - fonts/NotoSansKR-Thin.ttf
47
+ - fonts/NotoSansSC-Bold.ttf
48
+ - fonts/NotoSansSC-Regular.ttf
49
+ - fonts/NotoSansSC-Thin.ttf
50
+ - fonts/PublicSans-Bold.ttf
51
+ - fonts/PublicSans-BoldItalic.ttf
52
+ - fonts/PublicSans-Regular.ttf
53
+ - fonts/PublicSans-Thin.ttf
54
+ - fonts/PublicSans-ThinItalic.ttf
55
+ - fonts/Roboto-Bold.ttf
56
+ - fonts/Roboto-BoldItalic.ttf
57
+ - fonts/Roboto-Italic.ttf
58
+ - fonts/Roboto-Regular.ttf
59
+ - fonts/Roboto-Thin.ttf
60
+ - fonts/Roboto-ThinItalic.ttf
43
61
  - lib/thumb_gen.rb
44
62
  - lib/thumb_gen/generator.rb
63
+ - lib/thumb_gen/test.rb
45
64
  - lib/thumb_gen/utils.rb
46
65
  - lib/thumb_gen/version.rb
47
66
  - sample_input.jpg
@@ -54,7 +73,6 @@ metadata:
54
73
  allowed_push_host: https://rubygems.org
55
74
  homepage_uri: https://github.com/YutoYasunaga/thumb_gen
56
75
  source_code_uri: https://github.com/YutoYasunaga/thumb_gen.git
57
- post_install_message:
58
76
  rdoc_options: []
59
77
  require_paths:
60
78
  - lib
@@ -69,8 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
87
  - !ruby/object:Gem::Version
70
88
  version: '0'
71
89
  requirements: []
72
- rubygems_version: 3.5.18
73
- signing_key:
90
+ rubygems_version: 3.7.0
74
91
  specification_version: 4
75
92
  summary: Auto generate customized thumbnails for articles.
76
93
  test_files: []
data/default.png DELETED
Binary file