• Stars
    star
    212
  • Rank 186,122 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

descriptive-statistics

This gem calculates descriptive statistics including measures of central tendency (e.g. mean, median mode), dispersion (e.g. range, and quartiles), and spread (e.g variance and standard deviation).
Ruby
106
star
2

image_optimizer

This gem allows you to simply optimize images via jpegoptim or optipng.
Ruby
55
star
3

tracing-opentelemetry

Opentelemetry layer for the tracing crate
Rust
23
star
4

play-api

Play Framework standards for creating conventional applications
Shell
20
star
5

EmailToFace

A way to simply obtain a Facebook or Gravatar image from an email
Ruby
18
star
6

example-ember-rails-dashboard

Example dashboard using Ember.js and Rails
Ruby
13
star
7

sbt-jolokia

Jolokia support for any artifacts built with sbt-native-packager
Shell
12
star
8

example-rails-4.2-elastic-beanstalk-blog

Example blog hosted on AWS Elastic Beanstalk
Ruby
11
star
9

blog-react-rust-postgres

An example blog application with a react / redux front end and a rust / rocket / postgres backend
JavaScript
10
star
10

opentelemetry-rust

A Rust OpenTelemetry client
Rust
6
star
11

neo4j

Chef cookbook for installing Neo4j on AWS OpsWorks
Ruby
5
star
12

database_cleaner-remote_api

Simply creates an HTTP API for cleaning your database to be used by client tests.
Ruby
2
star
13

example-rails-elasticbeanstalk-blog

Ruby
2
star
14

retinafy

A jQuery plugin to retinafy images and background images
JavaScript
2
star
15

layer-scala

Scala library for interacting with the Layer API in an Akka or Play application.
Scala
2
star
16

jtescher.github.io

My Blog
CSS
2
star
17

factory_girl-remote_api

Simply creates an HTTP API for your FactoryGirl factories to be used by client tests.
Ruby
2
star
18

dotfiles-old

My Dotfiles
Vim Script
1
star
19

square-meals

Techcrunch hackathon project
Ruby
1
star
20

AName

Sweet Naming Site
JavaScript
1
star
21

data-pipeline-core

Example Spark Kafka Cassandra data pipeline
Scala
1
star
22

example-revel-app

Example Revel app written in go
Go
1
star
23

try_git

1
star
24

tokio-minidb

Toy database implementation written in Rust with Tokio
Rust
1
star
25

aoc-2023

Advent of Code 2023 in Rust
Rust
1
star
26

dotfiles

My dotfile config
Vim Script
1
star