Paperclip Utils
Paperclip Utils is a helper class for easier dynamic processors and styles on your Paperclip file uploads. It also has a collection of custom Paperclip processors.
Install
# requires ruby >= 2.0
gem install paperclip_utils
Custom Processors
Ghostscript - :ghostscript
- Fixes black boxes and errors thumbnail processing for PDF files. This is automatically included if processors includes :thumbnail which it does by default
XLS to CSV - :xls_to_csv
- Converts XLS/XLSX files to CSV
PDF Merge - :pdf_merge
- A way to handle multiple pdf uploads, requires some custom wiring, must add a pdf_files
method to your model and temporarily save files with this though.
Check the processor source to see examples if required. See all processors & examples here.
Helper Methods Usage
class Post < ActiveRecord::Base
:my_attachment,
styles: lambda{|x| Paperclip::Utils.get_styles(x.instance..content_type) },
processors: lambda{|x| Paperclip::Utils.get_processors(x..content_type) },
path: "public/system/:class/:attachment/:id_partition/:style/:filename",
url: "#{ActionController::Base.relative_url_root}/system/:class/:attachment/:id_partition/:style/:filename"
end
# OR using any or all of the custom options
class Post < ActiveRecord::Base
:my_attachment,
styles: lambda{|x| Paperclip::Utils.get_styles(x.instance..content_type, styles: {preview: "800x600>", thumb: "100x100>"}, fallback_styles: nil, allowed_content_types: ['application/pdf']) },
processors: lambda{|x| Paperclip::Utils.get_processors(x..content_type, processors: [:thumbnail, :some_other_custom_processor], fallback_processors: [:another_custom_processor], allowed_content_types: ['application/pdf']) },
path: "public/system/:class/:attachment/:id_partition/:style/:filename",
url: "#{ActionController::Base.relative_url_root}/system/:class/:attachment/:id_partition/:style/:filename"
end
Helper Methods & Options
Paperclip::Utils.get_styles(content_type, *optional_options)
styles - Array - Default: [:thumbnail]
fallback_styles - Hash - Default -{}
allowed_content_types - Array - Default: ['application/pdf', 'image/png', 'image/x-png', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/tif, ''image/tiff', 'image/x-tiff']
Paperclip::Utils.get_processors(content_type, *optional_options)
processors - Array - Default: [:ghostscript, :thumbnail]
- Notes: Automatically includes ghostscript processor if processors includes :thumbnail which it does by default
fallback_processors - Array - Default: []
allowed_content_types - Array - Default: ['application/pdf', 'image/png', 'image/x-png', 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/tif, ''image/tiff', 'image/x-tiff']
Credits
Created by Weston Ganger - @westonganger