在这种情况下,如何使用ImageMagick设置模型?

时间:2013-01-03 14:29:34

标签: ruby-on-rails ruby-on-rails-3 paperclip

我想将争论作为文本插入到用户上传的图像文件中 使用下面的代码,它不起作用。它只是保存图像而没有任何影响。
我正在使用名为'papaerclip'的宝石进行上传。

comment.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'" }

如何在此示例中插入图像底部的文字?
应该如何写 comment.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

1 个答案:

答案 0 :(得分:2)

它不喜欢你在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"' }