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.
- Multi-format Support: Convert text to
png,jpg,bmp, orwebpimages. - Smart Padding: Calculates the bounding box of the text and adds uniform padding on all four sides.
- Auto Font Detection: Automatically finds the best available system font using
fontconfig. - Customizable: Options for font size, specific font paths, background/foreground colors, and padding width.
This library requires ImageMagick and fontconfig to be installed on your system.
sudo apt update
sudo apt install imagemagick fontconfigbrew install imagemagick fontconfigAdd this line to your application's Gemfile:
gem 'text2image'And then execute:
$ bundle installrequire 'text2image'
# Save text to an image file (default 10px padding)
Text2image.convert("Hello, World!", output: "hello.png")
# With custom options including padding and format
Text2image.convert("Ruby is Awesome",
output: "ruby.webp",
font_size: 48,
padding: 30,
background: "#f0f0f0",
foreground: "blue",
format: "webp"
)Copyright (c) 2008-2026 Rheehose (Rhee Creative). Released under the MIT License.