text2image 1.1.0 → 1.3.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/CHANGELOG.md +7 -0
- data/CHANGELOG_ko.md +7 -0
- data/README.md +8 -7
- data/README_ko.md +26 -27
- data/lib/text2image/converter.rb +8 -6
- data/lib/text2image/version.rb +1 -1
- data/test_result.jpg +0 -0
- data/test_result.png +0 -0
- data/test_result.webp +0 -0
- data/verify_work.rb +20 -20
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40df9be876e9a4bfc5b544e0ee37162168ae00dafa9325f07feb9127c1dec2cc
|
|
4
|
+
data.tar.gz: d176b2852c38366933bcf28f8653b5fddeb4d10977adf857bf5fe100e6b19028
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7fdafbbb8ae9b888eab5cd9ac5eb096b3c1e9a5a2d86396e274c3892853690e61ae4bbfe8f4fcdc6373fca7d148b306dbd7063f2482bbec16d647a927a19ecae
|
|
7
|
+
data.tar.gz: 4653155990f44271e2ae537ad390ad1fcf1f44c5268f771b1ca5c92b1fd14a9012684c123212c2285eba15b6ccfc3ae3500e25240ae9feb7bbb2f9bd303dca86
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2026-01-15
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Multi-format Support**: Support for `png`, `jpg`/`jpeg`, `bmp`, and `webp`.
|
|
9
|
+
- **Customizable Background & Font**: Enhanced options to override default background and system font.
|
|
10
|
+
- **Improved Extension Detection**: Automatically detects output format from the file extension.
|
|
11
|
+
|
|
5
12
|
## [1.0.0] - 2026-01-15
|
|
6
13
|
|
|
7
14
|
### Added
|
data/CHANGELOG_ko.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2026-01-15
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Multi-format Support**: Support for `png`, `jpg`/`jpeg`, `bmp`, and `webp`.
|
|
9
|
+
- **Customizable Background & Font**: Enhanced options to override default background and system font.
|
|
10
|
+
- **Improved Extension Detection**: Automatically detects output format from the file extension.
|
|
11
|
+
|
|
5
12
|
## [1.0.0] - 2026-01-15
|
|
6
13
|
|
|
7
14
|
### Added
|
data/README.md
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
7
|
+
- **Multi-format Support**: Convert text to `png`, `jpg`, `bmp`, or `webp` images.
|
|
9
8
|
- **Smart Padding**: Calculates the bounding box of the text and adds uniform padding on all four sides.
|
|
10
|
-
- **
|
|
9
|
+
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
10
|
+
- **Customizable**: Options for font size, specific font paths, background/foreground colors, and padding width.
|
|
11
11
|
|
|
12
12
|
## Requirements
|
|
13
13
|
|
|
@@ -48,13 +48,14 @@ require 'text2image'
|
|
|
48
48
|
# Save text to an image file (default 10px padding)
|
|
49
49
|
Text2image.convert("Hello, World!", output: "hello.png")
|
|
50
50
|
|
|
51
|
-
# With custom options including padding
|
|
51
|
+
# With custom options including padding and format
|
|
52
52
|
Text2image.convert("Ruby is Awesome",
|
|
53
|
-
output: "ruby.
|
|
53
|
+
output: "ruby.webp",
|
|
54
54
|
font_size: 48,
|
|
55
55
|
padding: 30,
|
|
56
|
-
background: "
|
|
57
|
-
foreground: "
|
|
56
|
+
background: "#f0f0f0",
|
|
57
|
+
foreground: "blue",
|
|
58
|
+
format: "webp"
|
|
58
59
|
)
|
|
59
60
|
```
|
|
60
61
|
|
data/README_ko.md
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
# text2image
|
|
2
2
|
|
|
3
|
-
`text2image
|
|
3
|
+
`text2image` is a Ruby library that transforms text into black-on-white images. It automatically detects system fonts and generates optimized images with configurable padding around the text.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Multi-format Support**: Convert text to `png`, `jpg`, `bmp`, or `webp` images.
|
|
8
|
+
- **Smart Padding**: Calculates the bounding box of the text and adds uniform padding on all four sides.
|
|
9
|
+
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
10
|
+
- **Customizable**: Options for font size, specific font paths, background/foreground colors, and padding width.
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
- **자동 폰트 탐지**: `fontconfig`를 사용하여 시스템의 최적 폰트를 자동으로 찾습니다.
|
|
11
|
-
- **스마트 여백 (Smart Padding)**: 텍스트의 실제 크기를 계산하여 4방면에 균일한 여백을 자동으로 추가합니다.
|
|
12
|
-
- **유연한 설정**: 폰트 크기, 배경색, 글자색, 여백 크기 등을 자유롭게 조절할 수 있습니다.
|
|
12
|
+
## Requirements
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
이 라이브러리는 **ImageMagick**과 **fontconfig**가 시스템에 설치되어 있어야 합니다.
|
|
14
|
+
This library requires **ImageMagick** and **fontconfig** to be installed on your system.
|
|
17
15
|
|
|
18
16
|
### Linux (Ubuntu/Debian)
|
|
19
17
|
```bash
|
|
@@ -26,41 +24,42 @@ sudo apt install imagemagick fontconfig
|
|
|
26
24
|
brew install imagemagick fontconfig
|
|
27
25
|
```
|
|
28
26
|
|
|
29
|
-
##
|
|
27
|
+
## Installation
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
Add this line to your application's Gemfile:
|
|
32
30
|
|
|
33
31
|
```ruby
|
|
34
32
|
gem 'text2image'
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
And then execute:
|
|
38
36
|
|
|
39
37
|
```bash
|
|
40
38
|
$ bundle install
|
|
41
39
|
```
|
|
42
40
|
|
|
43
|
-
##
|
|
41
|
+
## Usage
|
|
44
42
|
|
|
45
|
-
###
|
|
43
|
+
### Basic Usage
|
|
46
44
|
|
|
47
45
|
```ruby
|
|
48
46
|
require 'text2image'
|
|
49
47
|
|
|
50
|
-
#
|
|
51
|
-
Text2image.convert("
|
|
52
|
-
|
|
53
|
-
#
|
|
54
|
-
Text2image.convert("Ruby",
|
|
55
|
-
output: "ruby.
|
|
56
|
-
font_size:
|
|
57
|
-
padding:
|
|
58
|
-
background: "
|
|
59
|
-
foreground: "
|
|
48
|
+
# Save text to an image file (default 10px padding)
|
|
49
|
+
Text2image.convert("Hello, World!", output: "hello.png")
|
|
50
|
+
|
|
51
|
+
# With custom options including padding and format
|
|
52
|
+
Text2image.convert("Ruby is Awesome",
|
|
53
|
+
output: "ruby.webp",
|
|
54
|
+
font_size: 48,
|
|
55
|
+
padding: 30,
|
|
56
|
+
background: "#f0f0f0",
|
|
57
|
+
foreground: "blue",
|
|
58
|
+
format: "webp"
|
|
60
59
|
)
|
|
61
60
|
```
|
|
62
61
|
|
|
63
|
-
##
|
|
62
|
+
## License
|
|
64
63
|
|
|
65
64
|
Copyright (c) 2008-2026 Rheehose (Rhee Creative).
|
|
66
|
-
|
|
65
|
+
Released under the [MIT License](LICENSE).
|
data/lib/text2image/converter.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'mini_magick'
|
|
|
4
4
|
|
|
5
5
|
module Text2image
|
|
6
6
|
class Converter
|
|
7
|
-
attr_accessor :text, :font, :font_size, :background, :foreground, :padding
|
|
7
|
+
attr_accessor :text, :font, :font_size, :background, :foreground, :padding, :format
|
|
8
8
|
|
|
9
9
|
def initialize(text, options = {})
|
|
10
10
|
@text = text
|
|
@@ -13,16 +13,18 @@ module Text2image
|
|
|
13
13
|
@background = options[:background] || "white"
|
|
14
14
|
@foreground = options[:foreground] || "black"
|
|
15
15
|
@padding = options[:padding] || 10
|
|
16
|
+
@format = options[:format] || "png"
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def render(output_path = nil)
|
|
19
20
|
require 'tempfile'
|
|
20
21
|
|
|
21
|
-
#
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
# Determine format from output_path if available, otherwise use @format
|
|
23
|
+
actual_format = output_path ? File.extname(output_path).delete('.').downcase : @format
|
|
24
|
+
actual_format = "png" if actual_format.empty?
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
# Step 1: Get text dimensions without padding
|
|
27
|
+
temp_raw = Tempfile.new(['text2image_raw', ".#{actual_format}"])
|
|
26
28
|
raw_path = temp_raw.path
|
|
27
29
|
temp_raw.close
|
|
28
30
|
|
|
@@ -46,7 +48,7 @@ module Text2image
|
|
|
46
48
|
final_width = width + (@padding * 2)
|
|
47
49
|
final_height = height + (@padding * 2)
|
|
48
50
|
|
|
49
|
-
temp_final = Tempfile.new(['text2image_final',
|
|
51
|
+
temp_final = Tempfile.new(['text2image_final', ".#{actual_format}"])
|
|
50
52
|
final_path = temp_final.path
|
|
51
53
|
temp_final.close
|
|
52
54
|
|
data/lib/text2image/version.rb
CHANGED
data/test_result.jpg
ADDED
|
Binary file
|
data/test_result.png
ADDED
|
Binary file
|
data/test_result.webp
ADDED
|
Binary file
|
data/verify_work.rb
CHANGED
|
@@ -7,29 +7,29 @@ begin
|
|
|
7
7
|
font_path = Text2image.find_font
|
|
8
8
|
puts "탐지된 시스템 폰트 경로: #{font_path}"
|
|
9
9
|
|
|
10
|
-
# 2. 이미지 생성 테스트 (
|
|
11
|
-
|
|
12
|
-
padding_value = 50
|
|
10
|
+
# 2. 이미지 생성 테스트 (다양한 포맷 및 옵션 확인)
|
|
11
|
+
formats = ["png", "jpg", "webp"]
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
puts "✅ 성공! 이미지가 생성되었습니다: #{File.expand_path(output_file)}"
|
|
13
|
+
formats.each do |fmt|
|
|
14
|
+
output_file = "test_result.#{fmt}"
|
|
15
|
+
puts "이미지 생성 중 (#{fmt} 포맷)..."
|
|
16
|
+
Text2image.convert("Ruby Text2Image v1.3\nFormat: #{fmt.upcase}",
|
|
17
|
+
output: output_file,
|
|
18
|
+
font_size: 35,
|
|
19
|
+
padding: 20,
|
|
20
|
+
background: (fmt == "webp" ? "#E0F7FA" : "white"),
|
|
21
|
+
foreground: (fmt == "webp" ? "#006064" : "black")
|
|
22
|
+
)
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
if File.exist?(output_file)
|
|
25
|
+
image = MiniMagick::Image.open(output_file)
|
|
26
|
+
puts "✅ 성공! #{fmt.upcase} 생성됨: #{image.width}x#{image.height}"
|
|
27
|
+
else
|
|
28
|
+
puts "❌ 실패: #{fmt.upcase} 생성 실패"
|
|
29
|
+
end
|
|
32
30
|
end
|
|
31
|
+
|
|
32
|
+
puts "모든 포맷 테스트 완료!"
|
|
33
33
|
|
|
34
34
|
rescue => e
|
|
35
35
|
puts "❌ 오류 발생: #{e.message}"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: text2image
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rheehose (Rhee Creative)
|
|
@@ -47,6 +47,9 @@ files:
|
|
|
47
47
|
- lib/text2image/font_finder.rb
|
|
48
48
|
- lib/text2image/version.rb
|
|
49
49
|
- test_padded_result.png
|
|
50
|
+
- test_result.jpg
|
|
51
|
+
- test_result.png
|
|
52
|
+
- test_result.webp
|
|
50
53
|
- text2image.gemspec
|
|
51
54
|
- verify_work.rb
|
|
52
55
|
homepage: https://github.com/hslcrb/rupack_text2image
|