How to optimize image uploaded via paperclip
Previously I wrote a post for saving image as progressive image, continuing the same, here is and another gem to reduce the size of the progressive image.
gem "paperclip-compression","~> 0.1.1"
Usage
class User < ActiveRecord::Base
has_attached_file :avatar,
:styles => { :medium => "300x300>", :thumb => "100x100>" },
:processors => [:thumbnail, :compression]
end
From previous learnings we can optimize this code as:
has_attached_file :attachment, {
:styles => {
:medium => ["654x500>", :jpg],
:thumb =>["200x200#", :jpg]
},
:convert_options => {
:medium => "-quality 80 -interlace Plane",
:thumb => "-quality 80 -interlace Plane"
}
},
:processors => [:thumbnail, :compression]
After using this optimization trick I am able to save approx 20% of image size in my projects. Pretty nice and clean.