No commit activity in last 3 years
No release in over 3 years
This gem is Paperclip processor which allow specify file processing based on his content type
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0

Runtime

 Project Readme

Paperclip::ContentTypeProcessor

Allows to add file processing by content type for paperclip attachments.

Requirements

libmagic

Installation

Add this line to your application's Gemfile:

gem 'paperclip-content_type_processor'

And then execute:

$ bundle

Or install it by yourself as:

$ gem install paperclip-content_type_processor

Usage

  1. Specify file processing per content type:
Paperclip::ContentTypeProcessor.add_content_type_processor("content/type", "command", "command arguments")
  1. Add content type processor for attachment:
has_attached_file :avatar,
    styles: { medium: '96x96#' },
    processors: [:thumbnail, :content_type_processor]
end

Example

It can be used for image compression/optimizations.

  1. Install image optimizers:

  2. Add initializer in your rails app config/initializers/content_type_processor.rb, and specify file processing per content type:

Paperclip::ContentTypeProcessor.add_content_type_processor("image/jpeg", "jpegoptim", "--strip-all --max=90")
Paperclip::ContentTypeProcessor.add_content_type_processor("image/png", "optipng", "-o6 -strip all")
  1. Enable content type processing for user avatars:
class User < ActiveRecord::Base
  has_attached_file :avatar,
    styles: { medium: '96x96#' },
    processors: [:thumbnail, :content_type_processor]
end

So all user avatars will be processed by 'jpegoptim' or 'optipng' according to its content type.

Note! If you want to generate thumbnails, you should also specify :thumbnails in processor list

Contributing

  1. Fork it ( http://github.com/ingeniarius/paperclip-content_type_processor/fork )
  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