Its a ruby gem to render your text to an image with fancy fonts and some effects with backgrounds. Might be suitable if you ever had to generate these kind of things automatically for using them as cover or header images. It makes use of ImageMagick for all image manipulations
I had a need for something like this for a project of mine and wasn't able to find anything that fit my use case.
Add this line to your application's Gemfile:
gem 'kawaii_text'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kawaii_text
require "kawaii_text"
By default, this gem randomly picks a background image and font along with a default color and some stroke styles. The output is saved to the same directory as the script is run in a file named "output.png".
KawaiiText::Generator.new(text: "Daisy in a field of roses")
The generator takes a lot of keyword arguments while initialization which can be used to modify various settings. The description of supported arguments and what they do are given below:
- text (required, string) - Specifies the text to be rendered.
KawaiiText::Generator.new(text: "Daisy in a field of roses")
- font_path (optional, string) - Specifies the font to be used (.ttf file). By default it randomly picks a font out of the 4 included with this library.
KawaiiText::Generator.new(text: "bury a friend", font_path: "/home/owaiswiz/Roboto.ttf")
- background_filepath (optional, string) - Specifies the background file to be used. By default, a folder with 4 backgrounds included with this library is used and a random file from that folder is selected.
KawaiiText::Generator.new(text: "bury a friend", backgrounds_folder: "/home/owaiswiz/images/rak.png")
- backgrounds_folder (optional, string) - Specifies the folder to be used for randomly picking a background. By default, a folder with 4 backgrounds included with this library is used. (Has no effect if background_filepath is specified).
KawaiiText::Generator.new(text: "bury a friend", backgrounds_folder: "/home/owaiswiz/images")
- supported_formats (optional, array of strings) - Specifies the file types to consider while randomly picking a background from backgrounds_folder. By default its value is ["jpg", "jpeg", "png", "gif"]. (Has no effect if background_filepath is specified).
KawaiiText::Generator.new(text: "bury a friend", backgrounds_folder: "/home/owaiswiz/images", supported_formats: ["png", "bmp"])
- working_directory (optional, string) - Specifies the path to the directory where output is saved. By default its value is the current directory from which you are running ruby.
KawaiiText::Generator.new(text: "bury a friend", working_directory: "/home/owaiswiz/generated_images")
- output_file_name (optional, string) - Specifies the name of the output file. By default its value is "output".
KawaiiText::Generator.new(text: "bury a friend", output_file_name: "uncomfortable.png")
- primary_text_layer_config (optional, PrimaryTextLayerConfig) - Configures the stroke size, stroke color and stroke fill color for the primary text layer.
config = KawaiiText::PrimaryTextLayerConfig.new
config.pointsize = 72
config.stroke_width = 5
config.stroke_color = "#e24906"
config.stroke_fill_color = "#dc9f66"
KawaiiText::Generator.new(text: "Jokes", primary_text_layer_config: config)
- offset_text_layer_config (optional, OffsetTextLayerConfig) - Configures the stroke size, stroke color and stroke fill color for the primary text layer.
config = KawaiiText::OffsetTextLayerConfig.default
config.stroke_color = "#59C3C3"
config.stroke_fill_color = "#DCB6D5"
config.stroke_fill_color = "none"
config.stroke_width = 2
KawaiiText::Generator.new text: "bury a friend", offset_text_layer_config: config
- Make sure you have ImageMagick installed.
- RMagick (should be automatically installed if not available)
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
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 tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/owaiswiz/kawaiitext.