RoR: How to create a dynamic text image with a specific font

I am looking for sample code for an example, preferably Ruby on Rails, on how to dynamically create an image containing text in a specific font.

Basically, I want to create a URL like this:

/api/text_as_image?font=futura&text=foo 

And return the image containing the text "foo" in the font "futura". I know that this can be done with ImageMagick, I just can't figure it out. Any help is appreciated.

+4
source share
1 answer

Check out the magick_title gem:

Here is the main use:

 # this could come from your form params[:magick_title] = { :font_size => 24, :color => '#ff0000' } # Then in your controller MagickTitle.say("Hello!", params[:magick_image]).to_html 
+5
source

Source: https://habr.com/ru/post/1337827/


All Articles