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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With