0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Helper class for easier dynamic processors and styles on your Paperclip uploads
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0
 Project Readme

Paperclip Utils

Gem Version RubyGems Downloads Buy Me a Coffee

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

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.

Helpers Methods

class Post < ActiveRecord::Base
  has_attachment :my_attachment, 
    styles: lambda{|x| Paperclip::Utils.get_styles(x.instance.my_attachment.content_type) }, 
    processors: lambda{|x| Paperclip::Utils.get_processors(x.my_attachment.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
  has_attachment :my_attachment, 
    styles: lambda{|x| Paperclip::Utils.get_styles(x.instance.my_attachment.content_type, styles: {preview: "800x600>", thumb: "100x100>"}, fallback_styles: nil, allowed_content_types: ['application/pdf']) }, 
    processors: lambda{|x| Paperclip::Utils.get_processors(x.my_attachment.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

Paperclip::Utils.get_styles(content_type, *optional_options)

Option Type Default Notes
styles Array { preview: '600x800>'} Default file type for each style is .jpg for uploaded .pdf and .tif file
fallback_styles Hash {} These are the styles applied if the files content type is in the allowed list below.
allowed_content_types Array ['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)

Option Type Default Notes
processors Array [:ghostscript, :thumbnail] Automatically includes ghostscript processor if processors includes :thumbnail which it does by default
fallback_processors Hash [] These are the processors applied if the files content type is in the allowed list below.
allowed_content_types Array ['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

Buy Me a Coffee