<commit_before># paperclip-compression
[![Gem Version](https://emrekutlu-test-1.appspot.com/gems/paperclip-compression/version.png)](https://rubygems.org/gems/paperclip-compression) [![Dependency Status](https://gemnasium.com/emrekutlu/paperclip-compression.png)](https://gemnasium.com/emrekutlu/paperclip-compression) [![Code Climate](https://codeclimate.com/github/emrekutlu/paperclip-compression.png)](https://codeclimate.com/github/emrekutlu/paperclip-compression)

JPEG and PNG compression processor for Paperclip. Under the hood, [jpegtran](http://jpegclub.org) and [optipng](http://optipng.sourceforge.net/) libraries are used.

## Installation

Add to your Gemfile.

````ruby
gem 'paperclip-compression'
````

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

````ruby
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 <code>thumb</code>.

````ruby
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
````
<commit_msg>updates README for 'command' option<commit_after># paperclip-compression
[![Gem Version](https://emrekutlu-test-1.appspot.com/gems/paperclip-compression/version.png)](https://rubygems.org/gems/paperclip-compression) [![Dependency Status](https://gemnasium.com/emrekutlu/paperclip-compression.png)](https://gemnasium.com/emrekutlu/paperclip-compression) [![Code Climate](https://codeclimate.com/github/emrekutlu/paperclip-compression.png)](https://codeclimate.com/github/emrekutlu/paperclip-compression)

JPEG and PNG compression processor for Paperclip. Under the hood, [jpegtran](http://jpegclub.org) and [optipng](http://optipng.sourceforge.net/) libraries are used.

## Installation

Add to your Gemfile.

````ruby
gem 'paperclip-compression'
````

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

````ruby
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 <code>thumb</code>.

````ruby
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
````

paperclip-compression uses binaries which are bundled with the gem. So you don't need to install anything. But if these binaries don't work for you, you can use your own.

````ruby
class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: {
      thumb: {
        geometry: '100x100>',
        processor_options: {
          compression: {
            jpeg: {
              command: '/path/to/jpegtran',
              options: '-copy none -optimize'
            }
          }
        }
      }
    },
    processors: [:thumbnail, :compression]
end
````

{'fraction_non_alphanumeric': 0.1355021216407355, 'fraction_numerical': 0.015841584158415842, 'mean_word_length': 3.4089775561097255, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1286371', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1092, 'n_words': 258}