簡體   English   中英

Ruby rmagick:如何使文本更粗體?

[英]Ruby rmagick: How to make text more bold?

def change_image_labels(feed_data)
 for data in feed_data
  img = Image::read(@tmpdir_file_path+"/#{data[0]}.png").first.resize(600,600)
 redback = Image::read("#{Rails.root}/tmp/redback.png")[0]
 txt = Magick::Draw.new
 redback.annotate(txt,0,0,0,0,data[2]){
   txt.gravity = Magick::WestGravity
   txt.pointsize = 50
   txt.fill = "#ffffff"
   txt.font_family = 'helvetica'
   txt.font_weight = Magick::BoldWeight
 }
 img = img.composite(redback, 0, 30, AtopCompositeOp)
 img.write(@tmpdir_file_path+"/#{data[0]}.png")
end
end

在這里,我嘗試為帶有reb背景的圖像添加文本注釋。

Here `redback.annotate(txt,0,0,0,0,data[2]` `data[2]` refers to the text which contains data like 92% OFF. I want to make it bold.

請參考以下圖片-

實際結果-

在此處輸入圖片說明

預期結果(大膽)-

在此處輸入圖片說明

盡力而為,第二個圖像包含一個更粗體的文本。

請幫忙。

我無法讓Helvetica對Rmagick顯得大膽。 最好的選擇是下載一個粗體字體 ,將其復制到Rails項目中,並告訴RMagick使用它:

txt.font = "#{Rails.root}/lib/fonts/[font filename].ttf"

如果您非常小心,可以使用以下命令使文本加粗(但可能更難看):

txt.stroke_width = 1 # <-- adjust this parameter
txt.stroke = "#ffffff"
txt.stroke_antialias true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM