Skip to content
프로젝트

jtescher/carrierwave-imageoptimizer

GitHub에서 보기

소개

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

디자인 및 미디어

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

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 Code Climate Coverage Status 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

관련 프로젝트 살펴보기

불러오는 중…