当高于600Kb而不是.gif:
时,尝试将最大宽度设置为1280has_attached_file :main_image,
:styles => {:original => "" },
:convert_options => {
:original => lambda { |instance| (instance.main_image_file_name.index(/\.gif/,-4).nil? && instance.main_image.size > 600000) ? "-resize 1280>" : "" }
},
:path => ":rails_root/public/system/:class/:attachment/:id_:basename.:extension",
:url => "/system/:class/:attachment/:id_:basename.:extension"
在我的日志中获取此信息:
Command :: convert '/var/folders/hn/2q5wpxh52nn_3nk9wwskr48w0000gn/T/5827912cb359afd550a72bf4f54b109020141119-76993-1i6nij6.png[0]' -auto-orient -resize 1280> '/var/folders/hn/2q5wpxh52nn_3nk9wwskr48w0000gn/T/5827912cb359afd550a72bf4f54b109020141119-76993-1i6nij620141119-76993-q0m833'
sh: 1280: Bad file descriptor
[paperclip] An error was received while processing: #<Paperclip::Error: There was an error processing the thumbnail for 5827912cb359afd550a72bf4f54b109020141119-76993-1i6nij6>
答案 0 :(得分:0)
这里有两个问题:
\\
或<
字符前添加>
,如1280x\\>
1280x\\>
而不是1280\\>
)。 这是我在600Kb以上而不是.gif时将最大宽度设置为1280的完整解决方案:
has_attached_file :main_image,
:styles => {:original => "" },
:convert_options => {
:original => lambda { |instance| (instance.main_image_file_name.index(/\.gif/,-4).nil? && instance.main_image.size > 600000) ? "-resize 1280x\\>" : "" }
},
:path => ":rails_root/public/system/:class/:attachment/:id_:basename.:extension",
:url => "/system/:class/:attachment/:id_:basename.:extension"