如何让rmagick包装图片上的注释文本,然后自动缩放字体大小并添加换行符?它就像一个模因生成器。
提前致谢
答案 0 :(得分:0)
phrase = 'Nullam quis risus eget urna mollis ornare vel eu leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Aenean lacinia bibendum nulla sed consectetur.'
BACKGROUND_PATH = Rails.root.join('image_dir', 'background.jpg')
background = Magick::Image.read(BACKGROUND_PATH).first
img = Magick::Image.read("caption:#{phrase}") do
# puts self.methods
self.size = '500x'
self.background_color = 'none'
self.pointsize = 30
self.font = 'Tahoma'
self.fill = 'gray'
self.gravity = Magick::CenterGravity #Text orientation
end.first
# Text box orientation #left(20), #right(40)
background.composite!(img, Magick::NorthEastGravity, 20, 40, Magick::OverCompositeOp)
background.write(Rails.root.join('tmp', 'my_image.jpg'))