在 Rmagic 中如何在带有标题的图像上添加行间距

use*_*245 5 ruby rmagick imagemagick

使用 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
Run Code Online (Sandbox Code Playgroud)

这给出了错误:

 undefined method `interline_spacing=' for #<Magick::Image::Info:0x00000101aad190> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)

如何在此处添加行距?

Gal*_*Gal 3

它是对象的属性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
Run Code Online (Sandbox Code Playgroud)