【问题标题】:Rounded corners with Paperclip带回形针的圆角
【发布时间】:2012-01-09 14:17:51
【问题描述】:

如何使用回形针创建圆角?我找到了这个创建rounded corners with paperclip using convert_options 的解决方案,但它不适用于 Rails 3 和 Paperclip 2.4.5。仅当我使用 ImageMagick alpha parameter 而不是阈值参数时,生成的转换命令才有效:

  convert example.jpg \
     \( +clone  -alpha extract \
        -draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
        \( +clone -flip \) -compose Multiply -composite \
        \( +clone -flop \) -compose Multiply -composite \
     \) -alpha off -compose CopyOpacity -composite  rounded_corners.png

对应

has_attached_file :avatar,
                  :styles => { :medium => ["918x483#", :png] },
                  :convert_options => {:medium => Proc.new{self.convert_options}}

def self.convert_options(px = 15)
  trans = ""
  trans << " \\( +clone  -alpha extract "
  trans << "-draw 'fill black polygon 0,0 0,#{px} #{px},0 fill white circle #{px},#{px} #{px},0' "
  trans << "\\( +clone -flip \\) -compose Multiply -composite "
  trans << "\\( +clone -flop \\) -compose Multiply -composite "
  trans << "\\) +alpha off -compose CopyOpacity -composite "
end

这段代码 sn-p 似乎产生了正确的转换命令,但给出了“处理 stream-xyz 的缩略图时出错”。

Command :: convert '/tmp/stream20120109-15817-1lju7p6-0.jpg[0]' -resize "918x" 
  -crop "918x483+0+105" +repage \( +clone -alpha extract -draw 'fill black polygon 
  0,0 0,15 15,0 fill white circle 15,15 15,0' \( +clone -flip \) -compose 
  Multiply -composite \( +clone -flop \) -compose Multiply -composite \) +alpha off
  -compose CopyOpacity -composite '/tmp/stream20120109-15817-1lju7p6-....png'
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: 
There was an error processing the thumbnail for stream20120109-15817-1lju7p6-0>

【问题讨论】:

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


    【解决方案1】:

    最后我发现了,这是一个简单的错字。您必须使用-alpha off 而不是+alpha off,然后上面的代码可以正常工作。有时一个符号(- 而不是 + 或反之亦然)会产生影响。

    【讨论】:

    • 感谢您回来告诉我们解决方案。它帮助了我。
    • 它可以工作,但只有 png,是否可以使用 jpg?
    猜你喜欢
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2017-12-04
    • 2012-10-20
    相关资源
    最近更新 更多