PaperclipOptimizer is a processor for Paperclip that allows you to optimize and minify uploaded JPG, PNG or GIF images.
It is just a thin wrapper around ImageOptim, which supports many external optimization libraries like
- advpng from AdvanceCOMP
- gifsicle
- jpegoptim
- jpegtran from Independent JPEG Group's JPEG library
- optipng
- pngcrush
- pngout
Add this line to your application's Gemfile after the Paperclip gem:
gem 'paperclip-optimizer'
And then execute:
$ bundle
See ImageOptims README on how to install the various optimization libraries.
If you deploy to Heroku, take a look at the image_optim_bin gem. It supplies the necessary optimization binaries, compiled and ready for Herokus environment.
gem "image_optim_bin", group: :production
gem "paperclip-optimizer"
Just add :paperclip_optimizer
to Paperclips :processors
- setting:
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
:styles => { :thumb => "100x100>" },
:default_url => "/images/:style/missing.png",
:processors => [:thumbnail, :paperclip_optimizer]
end
Remember to include the :thumbnail
processor as well if you want to retain
Paperclips geometry functionality.
By default, PaperclipOptimizer only enables jpegtran and optipng. You can
pass configuration options to ImageOptim through the :styles
hash:
class User < ActiveRecord::Base
attr_accessible :avatar
has_attached_file :avatar,
:styles => {
:thumb => {
:geometry => "100x100>",
:paperclip_optimizer => {
:pngout => {
:strategy => 1
}
}
}
},
:default_url => "/images/:style/missing.png",
:processors => [:thumbnail, :paperclip_optimizer]
end
See ImageOptims options for all available options.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request