Socket
Book a DemoInstallSign in
Socket

paperclip-content_type_processor

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paperclip-content_type_processor

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

  • Specify file processing per content type:
Paperclip::ContentTypeProcessor.add_content_type_processor("content/type", "command", "command arguments")
  • 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.

  • Install image optimizers:

    • jpegoptim (http://freecode.com/projects/jpegoptim)
    • optipng (http://optipng.sourceforge.net/)
  • 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")
  • 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

FAQs

Package last updated on 17 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.