Paperclip process images only

时间秒杀一切 提交于 2019-12-01 15:24:47

set :whiny option to false:

has_attached_file :my_attach, :whiny => false ...

it won't help peparclip to process images only, but it won't throw errors if processing failed

UPD

Processing for images only:

has_attached_file :file, 
  :styles => lambda{ |a| ["image/jpeg", "image/png"].include?( a.content_type ) ? { :small => "90x90#" } : {}  }

where you can add as more as you like content types into ["image/jpeg", "image/png"] array

You can also use paperclip's callback for post-processing of images, and instruct paperclip to only process images. If the before_post_process callback returns false, the processing stops.

    before_post_process :process_only_images

    def process_only_images
     %w(image/jpeg, image/png,image/gif,image/pjpeg, image/x-png).include?(attachment_content_type)
    end

Check paperclip's documentation for more details at https://github.com/thoughtbot/paperclip#events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!