PaperclipOptimizer

Build Status Dependency Status

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

Installation

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.

Usage

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.

Settings

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.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request