GithubHelp home page GithubHelp logo

dlackty / carrierwave-imageoptimizer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jtescher/carrierwave-imageoptimizer

0.0 3.0 0.0 27 KB

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

Home Page: https://rubygems.org/gems/carrierwave-imageoptimizer

License: MIT License

Ruby 100.00%

carrierwave-imageoptimizer's Introduction

CarrierWave ImageOptimizer

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

Tested against 2.2.x, 2.3.x, and ruby-head

[Build Status] (http://travis-ci.org/jtescher/carrierwave-imageoptimizer) [Dependency Status] (https://gemnasium.com/jtescher/carrierwave-imageoptimizer) [Code Climate] (https://codeclimate.com/github/jtescher/carrierwave-imageoptimizer) [Coverage Status] (https://coveralls.io/r/jtescher/carrierwave-imageoptimizer) Gem Version

Installation

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

  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

Installation on Heroku

If you are using Heroku for your production you must use heroku buildpacks in order to install optipng and jpegoptim. jayzes has some plug and play buildpacks to get you going in no time.

On an existing Heroku app and using the Heroku CLI

  1. Add this gem to your gemfile.
  2. Modify your code following the instrunctions on the usage section.
  3. heroku buildpacks:add --index 1 https://github.com/jayzes/heroku-buildpack-optipng
  4. heroku buildpacks:add --index 1 https://github.com/jayzes/heroku-buildpack-jpegoptim
  5. git push heroku
  • It is important to do a push to heroku after the buildpacks have been declared.

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

carrierwave-imageoptimizer's People

Contributors

bmayes avatar efexen avatar jtescher avatar mdesantis avatar olivierlacan avatar serodriguez68 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.