标题/标签方法不可用

2024-09-21 01:25:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用标题和/或标签在我的图片上写多行文字,但它不会在图片上写任何东西。你知道吗

def self.post_open_ended_response
  image = MiniMagick::Image.open("public/text_response_bg.png")
  image.combine_options do |i|
    i.size "460x"
    i.gravity 'center'
    i.fill 'white'
    i.pointsize '40'
    i.caption 'blahblahblah'
    # i.label "blahblah  fsdfsd fsd fsd fds fsd fds fds"
    # i.composite "public/output.jpg"
 end
 image.write "public/output.jpg"
end

我之所以要使用标题/标签而不是文本,是因为我读到imagemagick会神奇地缩放标题/标签的点大小。我的文本长度会有所不同,所以我不想硬编码。你知道吗


Tags: image文本标题outputresponse图片标签open
1条回答
网友
1楼 · 发布于 2024-09-21 01:25:32

对于任何其他人谁可能面临的问题在未来-更新到最新的创业板(目前4.2.0)。我是4.0.4版的,有个问题:

https://github.com/minimagick/minimagick/issues/191

更新-一般只需使用注解-它的工作。如果您需要文本操作,可以使用TextHelpers来完成。作为多行注释的示例,我完成了以下操作:

def create_og_image
  message = word_wrap('This is a test string. ' + @blog.title, line_width: 30).upcase

  image = MiniMagick::Image.open(@blog.image.path(:open_graph))
  image.combine_options do |c|
    #c.label message
    c.gravity 'NorthWest'
    c.fill 'white'
    c.stroke 'white'
    c.strokewidth '0'
    c.pointsize '70'
    c.interline_spacing '10'
    c.font "AvantGarde-Book"
    #c.size "500x300 label:'#{message}'"
    #c.label message
    c.annotate '+500+318', message

  end

  image.write "/xxx/xxx/xxx/public/test_image/test_output.jpg"
end

相关问题 更多 >

    热门问题