在Rmagic中如何使用标题在图像上添加行间距

时间:2014-08-28 17:19:35

标签: ruby imagemagick rmagick

使用Rmagic我正在执行以下操作来创建包含大量文本的图像

message="A very long auto wrapping sentence goes here"
  text_image = Image.read("caption:#{message}") do
  self.size="500x500"
  self.fill="white"
  self.background_color="#67c6ae"
  self.gravity=GravityType::WestGravity
  self.interline_spacing=5
end

这给出了错误:

 undefined method `interline_spacing=' for #<Magick::Image::Info:0x00000101aad190> (NoMethodError)

如何在此处添加行间距?

1 个答案:

答案 0 :(得分:2)

它是Draw对象的属性,而不是Image对象的属性。它适用于明确的换行符。至少那就是它如何为我工作:

image = Image.new(499,649)
message = "this\nmessage\nis\nmultiline"
draw = Draw.new
draw.annotate(image, 0,0,0,0,message) do
  self.gravity = NorthWestGravity
  self.pointsize = 32
  self.font_family = "Arial"
  self.font_weight = NormalWeight
  self.stroke = "none"
  self.fill = font_color
  self.interline_spacing = -5
end