jtescher/carrierwave-imageoptimizer
关于
This gem allows you to simply optimize CarrierWave images via jpegoptim or optipng.
设计与媒体实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文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
Installation
This gem uses the following utilities for optimizing images:
jpegoptim, which can be installed from the official jpegoptim repository
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
- Add this gem to your gemfile.
- Modify your code following the instrunctions on the usage section.
heroku buildpacks:add --index 1 https://github.com/jayzes/heroku-buildpack-optipngheroku buildpacks:add --index 1 https://github.com/jayzes/heroku-buildpack-jpegoptimgit 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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
探索相关项目
加载中…