text2image 1.0.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 +7 -0
- data/.gitignore +29 -0
- data/CHANGELOG.md +12 -0
- data/CHANGELOG_ko.md +12 -0
- data/CONTRIBUTING.md +47 -0
- data/CONTRIBUTING_ko.md +47 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/LICENSE_ko.md +21 -0
- data/README.md +64 -0
- data/README_ko.md +66 -0
- data/lib/text2image/converter.rb +80 -0
- data/lib/text2image/font_finder.rb +36 -0
- data/lib/text2image/version.rb +5 -0
- data/lib/text2image.rb +25 -0
- data/test_padded_result.png +0 -0
- data/text2image.gemspec +29 -0
- data/verify_work.rb +36 -0
- metadata +76 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bb0d3931cb713209d4e80ca9523e0ef0ce77d48196c0e90cd93c04625b4f6fbd
|
|
4
|
+
data.tar.gz: e5ddf3e583a8311733e10c218d3e1e421d44d254c4b9a7c3b331120d36b973c1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 86ccbdd21981642e01bee9983358dbb2684b89ae454021009f71a24ede88b4b2a8f9075380018cc5315c82b136f25d54b1fa1317c8da1029be6afb1cdf07a50a
|
|
7
|
+
data.tar.gz: 32eea1ac4e7840d28bd293f6694eec07ed0c40817561ea60484f3b4843038d19b47f02aed079dc5223e0f4071d478a67758dd68464fbe16ac45198c0d504c6c0
|
data/.gitignore
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
capybara-*.html
|
|
4
|
+
.rspec
|
|
5
|
+
/log
|
|
6
|
+
/tmp
|
|
7
|
+
/db/*.sqlite3
|
|
8
|
+
/db/*.sqlite3-journal
|
|
9
|
+
/public/system
|
|
10
|
+
/coverage/
|
|
11
|
+
/spec/tmp
|
|
12
|
+
**.orig
|
|
13
|
+
rerun.txt
|
|
14
|
+
pickle-email-*.html
|
|
15
|
+
|
|
16
|
+
# TODO: If you are using rspec, code coverage, or any other tool, add their
|
|
17
|
+
# files/directories here.
|
|
18
|
+
|
|
19
|
+
# Configuration
|
|
20
|
+
.env
|
|
21
|
+
|
|
22
|
+
# Dependencies
|
|
23
|
+
/vendor/bundle
|
|
24
|
+
/bundle/
|
|
25
|
+
/bin/
|
|
26
|
+
.bundle/
|
|
27
|
+
|
|
28
|
+
# Gemfile.lock
|
|
29
|
+
Gemfile.lock
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-01-15
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Initial Release**: Core text-to-image conversion features.
|
|
9
|
+
- **Smart Padding Control**: Added `padding` option to automatically add space around text by calculating the bounding box.
|
|
10
|
+
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
11
|
+
- **Bilingual Documentation**: Support for both English and Korean (`_ko.md`) documentation.
|
|
12
|
+
- **Verification Tools**: Included `verify_work.rb` for functionality testing and result verification.
|
data/CHANGELOG_ko.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-01-15
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Initial Release**: Core text-to-image conversion features.
|
|
9
|
+
- **Smart Padding Control**: Added `padding` option to automatically add space around text by calculating the bounding box.
|
|
10
|
+
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
11
|
+
- **Bilingual Documentation**: Support for both English and Korean (`_ko.md`) documentation.
|
|
12
|
+
- **Verification Tools**: Included `verify_work.rb` for functionality testing and result verification.
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contributing to text2image
|
|
2
|
+
|
|
3
|
+
먼저 `text2image`에 관심을 가져주셔서 감사합니다! 이 프로젝트에 참여하고 싶으시다면 다음 가이드를 따라주세요.
|
|
4
|
+
|
|
5
|
+
Thank you for your interest in contributing to `text2image`! To contribute, please follow these guidelines.
|
|
6
|
+
|
|
7
|
+
## How to Contribute
|
|
8
|
+
|
|
9
|
+
1. **Fork the repository** on GitHub.
|
|
10
|
+
2. **Clone your fork** to your local machine.
|
|
11
|
+
3. **Create a new branch** for your feature or bug fix:
|
|
12
|
+
```bash
|
|
13
|
+
git checkout -b feature/cool-new-feature
|
|
14
|
+
```
|
|
15
|
+
4. **Make your changes** and ensure they follow the code style.
|
|
16
|
+
5. **Write and run tests** (if applicable).
|
|
17
|
+
6. **Commit your changes** with a descriptive message:
|
|
18
|
+
```bash
|
|
19
|
+
git commit -m "Add a cool new feature"
|
|
20
|
+
```
|
|
21
|
+
7. **Push to your fork**:
|
|
22
|
+
```bash
|
|
23
|
+
git push origin feature/cool-new-feature
|
|
24
|
+
```
|
|
25
|
+
8. **Submit a Pull Request** to the `main` branch of the original repository.
|
|
26
|
+
|
|
27
|
+
## Development Setup
|
|
28
|
+
|
|
29
|
+
To share your development environment:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/rheehose/text2image.git
|
|
33
|
+
cd text2image
|
|
34
|
+
bin/setup
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Code of Conduct
|
|
38
|
+
|
|
39
|
+
Everyone interacting in the text2image project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
|
|
40
|
+
|
|
41
|
+
## Author
|
|
42
|
+
|
|
43
|
+
- **Rheehose (Rhee Creative)** - *Initial work* - [rheehose](https://github.com/rheehose)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
data/CONTRIBUTING_ko.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Contributing to text2image
|
|
2
|
+
|
|
3
|
+
먼저 `text2image`에 관심을 가져주셔서 감사합니다! 이 프로젝트에 참여하고 싶으시다면 다음 가이드를 따라주세요.
|
|
4
|
+
|
|
5
|
+
Thank you for your interest in contributing to `text2image`! To contribute, please follow these guidelines.
|
|
6
|
+
|
|
7
|
+
## How to Contribute
|
|
8
|
+
|
|
9
|
+
1. **Fork the repository** on GitHub.
|
|
10
|
+
2. **Clone your fork** to your local machine.
|
|
11
|
+
3. **Create a new branch** for your feature or bug fix:
|
|
12
|
+
```bash
|
|
13
|
+
git checkout -b feature/cool-new-feature
|
|
14
|
+
```
|
|
15
|
+
4. **Make your changes** and ensure they follow the code style.
|
|
16
|
+
5. **Write and run tests** (if applicable).
|
|
17
|
+
6. **Commit your changes** with a descriptive message:
|
|
18
|
+
```bash
|
|
19
|
+
git commit -m "Add a cool new feature"
|
|
20
|
+
```
|
|
21
|
+
7. **Push to your fork**:
|
|
22
|
+
```bash
|
|
23
|
+
git push origin feature/cool-new-feature
|
|
24
|
+
```
|
|
25
|
+
8. **Submit a Pull Request** to the `main` branch of the original repository.
|
|
26
|
+
|
|
27
|
+
## Development Setup
|
|
28
|
+
|
|
29
|
+
To share your development environment:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/rheehose/text2image.git
|
|
33
|
+
cd text2image
|
|
34
|
+
bin/setup
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Code of Conduct
|
|
38
|
+
|
|
39
|
+
Everyone interacting in the text2image project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct].
|
|
40
|
+
|
|
41
|
+
## Author
|
|
42
|
+
|
|
43
|
+
- **Rheehose (Rhee Creative)** - *Initial work* - [rheehose](https://github.com/rheehose)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2008-2026 Rheehose (Rhee Creative)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE_ko.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2008-2026 Rheehose (Rhee Creative)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# text2image
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Text to Image**: Convert any text string into a PNG/JPG image.
|
|
8
|
+
- **Auto Font Detection**: Automatically finds the best available system font using `fontconfig`.
|
|
9
|
+
- **Smart Padding**: Calculates the bounding box of the text and adds uniform padding on all four sides.
|
|
10
|
+
- **Customizable**: Options for font size, background/foreground colors, and padding width.
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
This library requires **ImageMagick** and **fontconfig** to be installed on your system.
|
|
15
|
+
|
|
16
|
+
### Linux (Ubuntu/Debian)
|
|
17
|
+
```bash
|
|
18
|
+
sudo apt update
|
|
19
|
+
sudo apt install imagemagick fontconfig
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### macOS
|
|
23
|
+
```bash
|
|
24
|
+
brew install imagemagick fontconfig
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Add this line to your application's Gemfile:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
gem 'text2image'
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
And then execute:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
$ bundle install
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### Basic Usage
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
require 'text2image'
|
|
47
|
+
|
|
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
|
|
52
|
+
Text2image.convert("Ruby is Awesome",
|
|
53
|
+
output: "ruby.png",
|
|
54
|
+
font_size: 48,
|
|
55
|
+
padding: 30,
|
|
56
|
+
background: "white",
|
|
57
|
+
foreground: "black"
|
|
58
|
+
)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
Copyright (c) 2008-2026 Rheehose (Rhee Creative).
|
|
64
|
+
Released under the [MIT License](LICENSE).
|
data/README_ko.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# text2image
|
|
2
|
+
|
|
3
|
+
`text2image`는 텍스트를 하얀 바탕에 검은색 글꼴로 자동화하여 이미지로 변환해주는 루비(Ruby) 라이브러리입니다. 시스템에 설치된 폰트를 자동으로 탐지하고, 텍스트 크기에 맞춰 여백(Padding)이 포함된 최적의 이미지를 생성합니다.
|
|
4
|
+
|
|
5
|
+
`text2image` is a Ruby library that transforms text into black-on-white images with automatic system font detection and smart padding adjustment.
|
|
6
|
+
|
|
7
|
+
## 주요 기능 (Features)
|
|
8
|
+
|
|
9
|
+
- **텍스트-이미지 변환**: 어떤 문자열이든 PNG/JPG 이미지로 변환합니다.
|
|
10
|
+
- **자동 폰트 탐지**: `fontconfig`를 사용하여 시스템의 최적 폰트를 자동으로 찾습니다.
|
|
11
|
+
- **스마트 여백 (Smart Padding)**: 텍스트의 실제 크기를 계산하여 4방면에 균일한 여백을 자동으로 추가합니다.
|
|
12
|
+
- **유연한 설정**: 폰트 크기, 배경색, 글자색, 여백 크기 등을 자유롭게 조절할 수 있습니다.
|
|
13
|
+
|
|
14
|
+
## 설치 요구사항 (Requirements)
|
|
15
|
+
|
|
16
|
+
이 라이브러리는 **ImageMagick**과 **fontconfig**가 시스템에 설치되어 있어야 합니다.
|
|
17
|
+
|
|
18
|
+
### Linux (Ubuntu/Debian)
|
|
19
|
+
```bash
|
|
20
|
+
sudo apt update
|
|
21
|
+
sudo apt install imagemagick fontconfig
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### macOS
|
|
25
|
+
```bash
|
|
26
|
+
brew install imagemagick fontconfig
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 설치 (Installation)
|
|
30
|
+
|
|
31
|
+
`Gemfile`에 다음 줄을 추가하세요:
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
gem 'text2image'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
그 후 아래 명령어를 실행합니다:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
$ bundle install
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 사용법 (Usage)
|
|
44
|
+
|
|
45
|
+
### 기본 사용 (Basic Usage)
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
require 'text2image'
|
|
49
|
+
|
|
50
|
+
# 텍스트를 이미지 파일로 저장 (기본 여백 10px 적용)
|
|
51
|
+
Text2image.convert("안녕하세요!", output: "hello.png")
|
|
52
|
+
|
|
53
|
+
# 옵션 설정 (여백 포함)
|
|
54
|
+
Text2image.convert("Ruby",
|
|
55
|
+
output: "ruby.png",
|
|
56
|
+
font_size: 50,
|
|
57
|
+
padding: 20,
|
|
58
|
+
background: "white",
|
|
59
|
+
foreground: "black"
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 저작권 및 라이선스 (License)
|
|
64
|
+
|
|
65
|
+
Copyright (c) 2008-2026 Rheehose (Rhee Creative).
|
|
66
|
+
이 라이브러리는 [MIT License](LICENSE) 하에 배포됩니다.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mini_magick'
|
|
4
|
+
|
|
5
|
+
module Text2image
|
|
6
|
+
class Converter
|
|
7
|
+
attr_accessor :text, :font, :font_size, :background, :foreground, :padding
|
|
8
|
+
|
|
9
|
+
def initialize(text, options = {})
|
|
10
|
+
@text = text
|
|
11
|
+
@font = options[:font] || FontFinder.find_font
|
|
12
|
+
@font_size = options[:font_size] || 24
|
|
13
|
+
@background = options[:background] || "white"
|
|
14
|
+
@foreground = options[:foreground] || "black"
|
|
15
|
+
@padding = options[:padding] || 10
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def render(output_path = nil)
|
|
19
|
+
require 'tempfile'
|
|
20
|
+
|
|
21
|
+
# Step 1: Get text dimensions without padding
|
|
22
|
+
# We use 'pango' or 'caption' if available for better text handling
|
|
23
|
+
# But for simplicity and portability, we use 'label' or 'caption' with trim
|
|
24
|
+
|
|
25
|
+
temp_raw = Tempfile.new(['text2image_raw', '.png'])
|
|
26
|
+
raw_path = temp_raw.path
|
|
27
|
+
temp_raw.close
|
|
28
|
+
|
|
29
|
+
# Render text on a large enough canvas then trim to find bounding box
|
|
30
|
+
MiniMagick::Tool::Convert.new do |c|
|
|
31
|
+
c.background @background
|
|
32
|
+
c.fill @foreground
|
|
33
|
+
c.font @font if @font
|
|
34
|
+
c.pointsize @font_size
|
|
35
|
+
c << "label:#{@text}"
|
|
36
|
+
c.trim
|
|
37
|
+
c << raw_path
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Step 2: Get dimensions of the trimmed text
|
|
41
|
+
trimmed_image = MiniMagick::Image.open(raw_path)
|
|
42
|
+
width = trimmed_image.width
|
|
43
|
+
height = trimmed_image.height
|
|
44
|
+
|
|
45
|
+
# Step 3: Create final image with padding
|
|
46
|
+
final_width = width + (@padding * 2)
|
|
47
|
+
final_height = height + (@padding * 2)
|
|
48
|
+
|
|
49
|
+
temp_final = Tempfile.new(['text2image_final', '.png'])
|
|
50
|
+
final_path = temp_final.path
|
|
51
|
+
temp_final.close
|
|
52
|
+
|
|
53
|
+
MiniMagick::Tool::Convert.new do |c|
|
|
54
|
+
c.size "#{final_width}x#{final_height}"
|
|
55
|
+
c.canvas @background
|
|
56
|
+
c.fill @foreground
|
|
57
|
+
c.font @font if @font
|
|
58
|
+
c.pointsize @font_size
|
|
59
|
+
c.gravity "Center"
|
|
60
|
+
c.draw "text 0,0 '#{@text.gsub("'", "\\\\'")}'"
|
|
61
|
+
c << final_path
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
image = MiniMagick::Image.open(final_path)
|
|
65
|
+
|
|
66
|
+
if output_path
|
|
67
|
+
image.write(output_path)
|
|
68
|
+
output_path
|
|
69
|
+
else
|
|
70
|
+
image
|
|
71
|
+
end
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
raise "Failed to render image: #{e.message}. Ensure ImageMagick is installed and accessible."
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def to_blob(format = "png")
|
|
77
|
+
render.format(format).to_blob
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
|
|
5
|
+
module Text2image
|
|
6
|
+
class FontFinder
|
|
7
|
+
class << self
|
|
8
|
+
def find_font(name = nil)
|
|
9
|
+
return name if name && File.exist?(name)
|
|
10
|
+
|
|
11
|
+
search_query = name || "sans-serif"
|
|
12
|
+
|
|
13
|
+
cmd = "fc-list \"#{search_query}\" :file"
|
|
14
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
|
15
|
+
|
|
16
|
+
if status.success? && !stdout.empty?
|
|
17
|
+
path = stdout.split("\n").first.split(":").first.strip
|
|
18
|
+
return path if File.exist?(path)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
fallback_fonts = [
|
|
22
|
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
23
|
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
|
24
|
+
"/usr/share/fonts/TTF/DejaVuSans.ttf",
|
|
25
|
+
"Arial"
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
fallback_fonts.each do |f|
|
|
29
|
+
return f if File.exist?(f) || f == "Arial"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
nil
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/text2image.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "text2image/version"
|
|
4
|
+
require_relative "text2image/font_finder"
|
|
5
|
+
require_relative "text2image/converter"
|
|
6
|
+
|
|
7
|
+
module Text2image
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def convert(text, options = {})
|
|
12
|
+
converter = Converter.new(text, options)
|
|
13
|
+
|
|
14
|
+
if options[:output]
|
|
15
|
+
converter.render(options[:output])
|
|
16
|
+
else
|
|
17
|
+
converter.render
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def find_font(name = nil)
|
|
22
|
+
FontFinder.find_font(name)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
Binary file
|
data/text2image.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/text2image/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "text2image"
|
|
7
|
+
spec.version = Text2image::VERSION
|
|
8
|
+
spec.authors = ["Rheehose (Rhee Creative)"]
|
|
9
|
+
spec.email = ["rheehose@example.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A Ruby library to convert text to images with automatic system font detection."
|
|
12
|
+
spec.description = "text2image allows you to easily transform text into black-and-white images using the best available system fonts. Ideal for quick image generation from text data."
|
|
13
|
+
spec.homepage = "https://github.com/rheehose/text2image"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = "exe"
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_dependency "mini_magick", "~> 4.12"
|
|
29
|
+
end
|
data/verify_work.rb
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require_relative 'lib/text2image'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
puts "--- text2image v1.1.0 최종 통합 테스트 ---"
|
|
5
|
+
|
|
6
|
+
# 1. 시스템 폰트 탐지 테스트
|
|
7
|
+
font_path = Text2image.find_font
|
|
8
|
+
puts "탐지된 시스템 폰트 경로: #{font_path}"
|
|
9
|
+
|
|
10
|
+
# 2. 이미지 생성 테스트 (스마트 여백 기능 확인)
|
|
11
|
+
output_file = "test_padded_result.png"
|
|
12
|
+
padding_value = 50
|
|
13
|
+
|
|
14
|
+
puts "이미지 생성 중 (여백: #{padding_value}px)..."
|
|
15
|
+
Text2image.convert("Ruby Text2Image\nSmart Padding Test",
|
|
16
|
+
output: output_file,
|
|
17
|
+
font_size: 40,
|
|
18
|
+
padding: padding_value,
|
|
19
|
+
background: "white",
|
|
20
|
+
foreground: "black"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
if File.exist?(output_file)
|
|
24
|
+
puts "✅ 성공! 이미지가 생성되었습니다: #{File.expand_path(output_file)}"
|
|
25
|
+
|
|
26
|
+
# 3. 실제 이미지 크기 확인 (여백이 잘 들어갔는지 간접 확인)
|
|
27
|
+
image = MiniMagick::Image.open(output_file)
|
|
28
|
+
puts "생성된 이미지 크기: #{image.width}x#{image.height}"
|
|
29
|
+
puts "테스트 완료!"
|
|
30
|
+
else
|
|
31
|
+
puts "❌ 실패: 이미지가 생성되지 않았습니다."
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
rescue => e
|
|
35
|
+
puts "❌ 오류 발생: #{e.message}"
|
|
36
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: text2image
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rheehose (Rhee Creative)
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-01-15 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: mini_magick
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '4.12'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '4.12'
|
|
26
|
+
description: text2image allows you to easily transform text into black-and-white images
|
|
27
|
+
using the best available system fonts. Ideal for quick image generation from text
|
|
28
|
+
data.
|
|
29
|
+
email:
|
|
30
|
+
- rheehose@example.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- ".gitignore"
|
|
36
|
+
- CHANGELOG.md
|
|
37
|
+
- CHANGELOG_ko.md
|
|
38
|
+
- CONTRIBUTING.md
|
|
39
|
+
- CONTRIBUTING_ko.md
|
|
40
|
+
- Gemfile
|
|
41
|
+
- LICENSE
|
|
42
|
+
- LICENSE_ko.md
|
|
43
|
+
- README.md
|
|
44
|
+
- README_ko.md
|
|
45
|
+
- lib/text2image.rb
|
|
46
|
+
- lib/text2image/converter.rb
|
|
47
|
+
- lib/text2image/font_finder.rb
|
|
48
|
+
- lib/text2image/version.rb
|
|
49
|
+
- test_padded_result.png
|
|
50
|
+
- text2image.gemspec
|
|
51
|
+
- verify_work.rb
|
|
52
|
+
homepage: https://github.com/rheehose/text2image
|
|
53
|
+
licenses:
|
|
54
|
+
- MIT
|
|
55
|
+
metadata:
|
|
56
|
+
homepage_uri: https://github.com/rheehose/text2image
|
|
57
|
+
source_code_uri: https://github.com/rheehose/text2image
|
|
58
|
+
changelog_uri: https://github.com/rheehose/text2image/blob/main/CHANGELOG.md
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 2.6.0
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0'
|
|
72
|
+
requirements: []
|
|
73
|
+
rubygems_version: 3.6.2
|
|
74
|
+
specification_version: 4
|
|
75
|
+
summary: A Ruby library to convert text to images with automatic system font detection.
|
|
76
|
+
test_files: []
|