Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails / Ruby - What gem can create a image with text?

Example I have a image.

enter image description here

In my controller I example have @name = "Jon"

Now I want to create a new image as the image I got just with the name "Jon" in the middle of the image. I want to be able to specify the font-size, color and font-family that should be used and the position of the text.

enter image description here

What gem are able to do that?

like image 611
Rails beginner Avatar asked Apr 24 '12 18:04

Rails beginner


1 Answers

A basic rmagick solution isn't that bad, 6 lines. The following gives you a yellow rectangle with TEXT in the center. You can experiment with the font and point size. The center call is there because I thought it looked better in the middle.

require 'RMagick'

canvas = Magick::Image.new(300, 100){self.background_color = 'yellow'}
gc = Magick::Draw.new
gc.pointsize(50)
gc.text(30,70, "TEXT".center(14))

gc.draw(canvas)
canvas.write('tst.png')

I get the requirement, you can also go through. This should help.

like image 96
123 Avatar answered Oct 30 '22 13:10

123