如何使 rmagick 将注释文本包装在图片上,然后自动缩放字体大小并添加换行符?它适用于模因生成器之类的东西。
提前致谢
如何使 rmagick 将注释文本包装在图片上,然后自动缩放字体大小并添加换行符?它适用于模因生成器之类的东西。
提前致谢
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'))