Paperclip stores original images in "original" folder. Is there a way to resize the original images? I want to make the originals smaller in order to save the disc space.
So, for example, if visitor uploads a photo开发者_运维百科 with 2592x1936 I want to store it as 1024x1024, the same way we set the dimensions for :thumb images in :styles
Update (solved)
I found out how to resize original images automatically on upload. One just needs to add :original to styles:
class MyModel < ActiveRecord::Base
has_attached_file :photo,
:styles => { :original => "1024x1024>", :thumb => "150x150>" }
end
I'm not sure paperclip does resizing by itself. You might have to look at Rmagick to get this done. I would try to get RMagick going (or minimagick) and then use a before_save callback to execute a :resize
method that you write that tells RMagic to resize the image. Your method might look like:
class Image < ActiveRecord::Base
belongs_to :profile
before_save :resize
def resize
self.image = self.image.resize "1024x1024"
end
end
or
class Image < ActiveRecord::Base
belongs_to :profile
before_save do
self.image = self.image.resize "1024x1024"
end
end
精彩评论