如何将Paperclip图像添加到数据库后调整其大小?

mcu*_*ulp 18 ruby-on-rails paperclip

我已经在我的图像表中添加了2000张图片,而我正在使用Paperclip插件创建拇指.我想知道是否有办法通过数据库并添加另一个:styles元素.

例如,当我添加图像时,我在模型中有以下内容:

has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
Run Code Online (Sandbox Code Playgroud)

但是,现在我想添加一个:large属性并将其应用于我表中已有的每个图像.就像是:

has_attached_file :image, :styles => { :large => "800x800>", :medium => "300x300>", :thumb => "100x100>" }
Run Code Online (Sandbox Code Playgroud)

这可能吗?或者我是否需要重新添加所有2000张照片?

Jon*_*man 42

如果Paperclip作为插件安装,您可以这样做:

rake paperclip:refresh:thumbnails CLASS=Screenshot
Run Code Online (Sandbox Code Playgroud)

其中,屏幕截图是带附件的类的名称.

如果它是作为gem安装的,请在脚本/控制台中执行此操作:

Screenshot.all.each {|s| s.image.reprocess! }
Run Code Online (Sandbox Code Playgroud)

用适当的类名替换屏幕截图

  • 如果你有大量的截图,你应该使用#find_each.Screenshot.find_each {| s | s.image.reprocess!} (2认同)

mcu*_*ulp 6

rake paperclip:refresh:thumbnails
Run Code Online (Sandbox Code Playgroud)

  • 对我来说更具体:rake paperclip:refresh:缩略图CLASS = MyClass (2认同)