回形针仅处理图像 [英] Paperclip process images only

查看:137
本文介绍了回形针仅处理图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将单个文件字段用于多种格式。据我所知,Paperclip非常聪明,只能缩放图像并保留其他格式,但这似乎不适用于flv(返回imagemagick / identify-errors)。是否有任何方法可以帮助Paperclip并明确设置特定格式以进行扩展?

I would like to use a single file-field for multiple formats. It was my understanding that Paperclip was smart enough to only scale images and leave other formats alone, but this doesn't seem to work for flv's (which returns imagemagick/identify-errors). Is there any way to help Paperclip a bit and explicitly setup specific formats to scale?

更新:
显然,这些错误是阻止:whiny => false(谢谢fl00r),适用于常规上传。
但是,我在这里要做的是通过FTP上传文件,然后在attachment-parameter中使用File.new([:path])创建一个新记录。这就像是图像的魅力,但是:whiny => false-trick将不再这样做了。有没有人对此有任何提示?

UPDATE: Apparently, these errors are prevented with :whiny=>false (thanks fl00r), which works fine for regular uploads. However, what I'm trying to do here is uploading the file by FTP, and later on create a new record by code with a File.new([:path]) in the attachment-parameter. This works like a charm for images, but the :whiny=>false-trick won't do it anymore. Does anyone has any tips on this?

推荐答案

设置:whiny 选项为假:

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

它不会帮助peparclip仅处理图像,但它不会抛出处理失败时出错

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

UPD

仅处理图片:

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

您可以根据需要添加更多内容类型 [image / jpeg,image / png] 数组

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

这篇关于回形针仅处理图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆