在rails 5.2.1中,我试图使用minimagick在图像上编写文本。问题是,对于长文本,它超出了图像宽度的限制。
我试图使用
draw
,
label
,
annotation
和
caption
方法从
here
但没有人给我正确的结果。
字幕
甚至不将文本添加到图像中。
这是我的代码:
temp_img = MiniMagick::Image.open(url_for(@post.image))
img_width = temp_img[:width]
temp_img.combine_options do |c|
c.gravity 'North'
c.draw "text 0, 0 '#{top_txt}'"
#c.annotate '0,0', "'#{top_txt}'" (same result)
#c.caption "'#{top_txt}'" (same result)
#c.label "'#{top_txt}'" (same result)
c.gravity 'South'
c.draw "text 0, 0 '#{bot_txt}'"
#c.annotate '0,0', "'#{bot_txt}'" (same result)
#c.caption "'#{bot_txt}'" (same result)
#c.label "'#{bot_txt}'" (same result)
c.stroke('#000000')
c.strokewidth 1
c.fill('#FFFFFF')
c.size "#{img_width}x"
c.pointsize '40'
c.font "#{Rails.root.join('public', 'font',
'Franklin_Gothic_Heavy_Regular.ttf')}"
end
这是我的结果:
我看到的最接近解决方案是
this
但是太乱了。
有更好的办法吗?