Skip to content

PriyankBhatt/paperclip-compression

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paperclip-compression

Gem Version Dependency Status Code Climate

JPEG and PNG compression processor for Paperclip. Under the hood, jpegtran and optipng libraries are used.

Installation

Add to your Gemfile.

gem 'paperclip-compression'

Usage

This is the basic usage. This will compress both JPEG and PNG files with the default options.

class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: { medium: '300x300>', thumb: '100x100>' },
    processors: [:thumbnail, :compression]
end

Disable PNG compression and change default options for JPEG compression for thumb.

class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: {
      medium: '300x300>',
      thumb: {
        geometry: '100x100>',
        processor_options: {
          compression: {
            png: false,
            jpeg: '-copy none -optimize'
          }
        }
      }
    },
    processors: [:thumbnail, :compression]
end

Defaults

Default options for jpegtran is -copy none -optimize -perfect and default options for optipng is -o 5.

You can use paperclip's default options to define global defaults for all your paperclip attachments. Use compression key.

Example for config/application.rb:

module YourApp
  class Application < Rails::Application
    # Other code...

    config.paperclip_defaults = { :compression => { :png => false, :jpeg => '-optimize' } }
  end
end

Example for Rails initializer:

Paperclip::Attachment.default_options[:compression] = { :png => false, :jpeg => '-optimize' }

For more information about paperclip defaults: https://github.com/thoughtbot/paperclip#defaults

License

paperclip-compression is released under the MIT License.

About

image compression processor for Paperclip

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%