2013-10-24 147 views
2

我遵循jcrop rails教程,但我碰到了一个障碍。事实上,回形针是从原始文件生成缩略图,但我需要它从另一种样式生成。原始文件在产品镜头和文档边缘之间没有空格。所以我不能进一步收获。为了解决这个问题,我制作了另一种具有白色像素填充的风格。这就是我想从中生成缩略图的原因。Rails回形针从其他风格生成缩略图

# croppable is the one with the padding...it's what shows up in the crop view. 
# I want :thumb to be generated from THAT style, not :original. 
# When generating from :original, the crop offset/size is screwed because the dimensions of :original don't match :cropped 
# and I can't crop beyond the pixel dimensions of :original. 
has_attached_file :photo, :styles => { 
        :thumb => { :geometry => "300x300#", :format => :jpg, :processors => [:cropper] }, 
        :general => ["150x375", :jpg], 
        :show => ["x425", :jpg], 
        :croppable => ["1200x1200>", :jpg] 
     }, 
     :url => "/assets/wines/:style/:wine_name", 
     :path => ":rails_root/public:url", 
     :default_url => ":wine_default", 
     :default_path => ":rails_root/public:wine_default", 
     :default_style => :show, 
     :convert_options => { 
      :thumb => '-gravity center -rotate -30', 
      :croppable => '-gravity center -extent 1200x1200', 
      :general => '-gravity center -extent 150x375 -quality 95', 
      :all => '-quality 100 -antialias -flatten -background white -unsharp 0.3x0.3+5+0' 
     }, 
     :processors => [:thumbnail, :compression] 

回答

3

我遇到了一个处理器,其他人已经在线并将其用于自己。有关高级使用信息,请参阅http://pjkh.com/articles/speeding-up-thumbnail-generation-with-paperclip/

recursive_thumbnail.rb(LIB中包含/ paperclip_processors)

module Paperclip 
    class RecursiveThumbnail < Thumbnail 
     def initialize file, options = {}, attachment = nil 
     super Paperclip.io_adapters.for(attachment.styles[options[:thumbnail] || :original]), options, attachment 
     end 
    end 
end 

和模型:

:styles => { 
    :croppable => ["1200x1200>", :jpg], 
    :show => ["x425", :jpg], 
    :general => ["150x375", :jpg], 
    :thumb => { 
     :geometry => "150x150^", 
     :format => :jpg, 
     :processors => [:recursive_thumbnail] }, 
     :thumbnail => :croppable 
    } 
0

也许这会帮助你或别人像我这样谁谷歌导致这一题。

https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation

生成/再生的缩略图

注:为所有 其他样式 描述了一些下面的例子中会导致断路径/网址只有再生的几个定义样式之一如果您的paperclip_defaults [:path]中有:hash,并且在您的paperclip_defaults [:hash_data]中有 :updated_at(并且您有 默认值)。除非你真的知道你在做什么,否则不要这样做。

您可以使用Paperclip的耙子 任务(重新)生成缩略图。使用我们上面的示例类:

bundle exec rake paperclip:refresh:thumbnails CLASS=User