No commit activity in last 3 years
No release in over 3 years
A simple image optimize for CarrierWave
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

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

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