Giter Site home page Giter Site logo

kimsuelim / carrierwave-imageoptimizer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jtescher/carrierwave-imageoptimizer

0.0 2.0 0.0 240 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

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 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] (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 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

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.