RAILS + PaperClip - 仅存储调整大小的图像

RAILS + PaperClip - store resized image only

我的模型看起来像:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :small => "50x50#" },
                    :default_style => :small                   

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg",   
                                      "image/gif", "image/png"] }
end

RAILS 将图像存储两次:原始大小,以及 :small 中定义的调整大小。我只想存储调整大小的图像。

我相信您可以简单地为 :original 定义一个样式,让回形针用该尺寸替换原件。

:styles => { :original => '300x168>', :cropped_thumb => {:geometry => "50x50#", :jcrop => true}, ...}

谢谢你,puneet18。

这个模型可以胜任:

class Photo < ApplicationRecord
  has_attached_file :image, 
                    :styles => { :original => "50x50#" },
                    :default_style => :original

  validates_attachment :image,
                       content_type: { content_type: ["image/jpeg", "image/gif",
                                       "image/png"] }
end