Rails / Ruby - What stone can create an image with text?

Example. I have an image.

enter image description here

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

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

enter image description here

What gemstone can do this?

+6
source share
2 answers

The basic rmagick solution is not so bad, 6 lines. Below is a yellow rectangle with text in the center. You can experiment with font and dot size. The central challenge 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 a request, you can also go through. This should help.

+8
source

I can’t comment, but if someone is working with the same problem as @andrhamm [cannot read the font (null)], install ghostscript and try again

+2
source

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


All Articles