CarrierWave ImageOptimizer

This gem allows you to simply optimize CarrierWave images via jpegoptim or optipng using the image_optimizer gem.

Tested against 1.9.3, 2.0.0, 2.1.0, ruby-head, jruby-19mode, jruby-head, rbx-2.1.1, rbx-2.2.0, and rbx-2.2.1

Build Status Dependency Status Code Climate Coverage Status Gem Version

Installation

This gem uses the following utilities for optimizing images:
  1. jpegoptim, which can be installed from freecode.com

  2. OptiPNG, which can be installed from sourceforge.net

Or install the utilities via homebrew:

$ brew install optipng jpegoptim

Then add this line to your application's Gemfile:

gem 'carrierwave-imageoptimizer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install carrierwave-imageoptimizer

Usage

To add image optimization to your CarrierWave uploader, first include the module:

class MyUploader < CarrierWave::Uploader::Base
  include CarrierWave::ImageOptimizer
  ...
end

Then apply to all versions via:

class MyUploader < CarrierWave::Uploader::Base
  ...
  process :optimize
end

Or to a single image version via:

class MyUploader < CarrierWave::Uploader::Base
  ...
  version :thumbnail do
    process :optimize
  end
end
Lossy JPEG optimization

Pass an optional quality parameter to target a specific lossy JPG quality level (0-100), default is lossless optimization. PNGs will ignore the quality setting.

class MyUploader < CarrierWave::Uploader::Base
  ...
  version :thumbnail do
    process :optimize, quality: 50
  end
end
Quiet Mode

Pass an optional quiet parameter to compress images without logging progress.

class MyUploader < CarrierWave::Uploader::Base
  ...
  version :thumbnail do
    process :optimize, quiet: true
  end
end

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