Skip to main content
 首页 » 编程设计

ruby-on-rails之在这种情况下,如何使用 ImageMagick 设置我的模型

2024年12月31日16hnrainll

我想将争论作为文本插入到用户上传的图像文件中。
使用下面的代码,它不起作用。它只是保存图像而没有任何效果。
我正在使用名为“papaeclip”的 gem 进行上传。

评论.rb

#paperclip 
has_attached_file :comment_icon, 
    :styles => { 
    :thumb=> "100x100>", 
    :small  => "400x400>" },  
    :convert_options => { 
    :all => " -stroke '#000C' -strokewidth 2 -annotate 0 'Faerie Dragon' -stroke  none   -fill white    -annotate 0 'Faerie Dragon'" } 

如何在此示例中将文本插入图像底部?
如何 评论.rb 应该写?

ImageMagick 代码
  convert dragon.gif -gravity south \ 
          -stroke '#000C' -strokewidth 2 -annotate 0 'Faerie Dragon' \ 
          -stroke  none   -fill white    -annotate 0 'Faerie Dragon' \ 
          anno_outline.jpg 

请您参考如下方法:

它不喜欢您在 convert_options 中的单引号。尝试使用:

' -gravity south -stroke "#000C" -strokewidth 2 -annotate 0 "Faerie Dragon" -stroke none -fill white -annotate 0 "Faerie Dragon"' 

反而。我正在使用 Paperclip 3.2.0 并且能够通过更改引号使其应用文本。

这是我的图像属性:
has_attached_file :avatar, 
:styles => {:large => "300x300", :medium => "140x140>", :thumb => "100x100>", :tiny => "50x50" }, 
:storage => :s3, 
:s3_credentials => "#{Rails.root}/config/amazons3.yml", 
:path => "avatars/:id/:style_:filename", 
:convert_options => { 
:all => ' -gravity south -stroke "#000C" -strokewidth 2 -annotate 0 "Faerie Dragon" -stroke none -fill white -annotate 0 "Faerie Dragon"' }