CarrierWave OptimizeImage
This gem allows you to simply optimize CarrierWave images via jpegoptim or optipng using the image_optimizer gem.
Installation
Add this line to your application's Gemfile:
This gem uses the following utilities for optimizing images:
Or install the utilities via homebrew:
$ brew install pngquant jpegoptim
Add this line to your application's Gemfile:
gem "carrierwave-optimize_image"
And then execute:
$ bundle
Or install it yourself as:
$ gem install carrierwave-optimize_image
Usage
To add image optimization to your CarrierWave uploader, first include the module:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::OptimizeImage
...
end
Then apply to all versions via:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::OptimizeImage
...
process :optimize
end
Or to a single image version via:
class ImageUploader < CarrierWave::Uploader::Base
...
version :thumbnail do
process :optimize
end
end
Pass an optional quality parameter to target a specific lossy JPG and PNG quality level (0-100)
class ImageUploader < CarrierWave::Uploader::Base
version :thumbnail do
process optimize: [{ quality: 60 }]
end
end
Quiet Mode
Pass an optional quiet
parameter to compress images without logging progress.
class ImageUploader < CarrierWave::Uploader::Base
...
version :thumbnail do
process optimize: [{ quiet: true }]
end
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b new_feature_branch
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin new_feature_branch
) - Create new Pull Request