【问题标题】:How do I apply a drop shadow to thumbnails using imagemagick and paperclip?如何使用 imagemagick 和回形针将阴影应用于缩略图?
【发布时间】:2009-07-22 20:16:50
【问题描述】:

我想通过让 imagemagick 对所有缩略图应用投影来更改回形针中缩略图的处理。我坚持的是实际的 imagemagick 命令,它将拉开这个小奇迹。我尝试过的所有操作都会返回一个不正确缩放的阴影,而没有原始图像。

def transformation_command
  scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
  trans = ""
  trans << " -resize \"#{scale}\""
  trans << " -crop \"#{crop}\" +repage" if crop
  # Apply Drop Shadow
  trans << " #{convert_options}" if convert_options? 
  trans
end

我试过的一个...

def transformation_command
  scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
  trans = ""
  trans << " -resize \"#{scale}\""
  trans << " -crop \"#{crop}\" +repage" if crop
  trans << " \( +clone -background black -shadow 60x5+10+10 \) +swap -background none -layers merge +repage"
  trans << " #{convert_options}" if convert_options? 
  trans
end

我是 imagemagick 的新手,任何帮助将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ruby imagemagick paperclip


    【解决方案1】:

    经过一些试验和错误并埋头于文档中,我终于弄明白了。

    has_attached_file :image, 
      :styles => { :thumb => ["100x100#", :png] }, 
      :convert_options => { :thumb => '\( +clone -background black -shadow 70x4+0+0 \) +swap -background none -layers merge +repage' }
    
    1. 确保您安装了最新版本的 ImageMagick。
    2. ["100x100#", :png] 会将图像转换为 png,因此投影是透明的。
    3. 在转换选项下,:thumb 只会将转换应用于 :thumb 样式,使用 :all 将转换应用于所有样式。
    4. 调整“70x4+0+0”以获得所需的阴影。

    【讨论】:

      【解决方案2】:

      我发现只使用 rmagick 界面而不是向 imagemagick 本身发送命令行选项要容易得多。

      如果你使用 rmagick,你可以使用 shadow 方法。

      img = Image.read('slide.png').first
      shadow = img.shadow(0, 0, 0.0, '20%')
      

      然后在阴影上合成图像。

      我写了一篇关于使用rmagick的文章:http://schf.uc.org/articles/2006/10/18/render-greatlooking-collages-with-ruby-and-rmagick

      尝试阅读它可能会让您更好地理解。

      我还为 rmagick 编写了一个抽象库,试图使其更易于使用。 我称它为RubyShop,因为它试图模仿基于 Photoshop 图层的合成..(我真的很讨厌这个名字,如果我重新启动这个项目可能会改变它)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-07
        • 1970-01-01
        • 1970-01-01
        • 2014-12-08
        • 2011-03-30
        • 2012-01-11
        相关资源
        最近更新 更多