找到了解决方案。这是一个棘手的问题,但它有效。创建了一个补丁paperclip-3.3.1
:
diff -r --unidirectional-new-file paperclip-3.3.1/lib/paperclip/geometry.rb paperclip-3.3.1-my/lib/paperclip/geometry.rb
23c23
< Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]")
---
> Paperclip.run("identify", "-format %wx%h :file", :file => file_path)
31c31
< raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command."))
---
> raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command. (from #{file.inspect})"))
diff -r --unidirectional-new-file paperclip-3.3.1/lib/paperclip/thumbnail.rb paperclip-3.3.1-my/lib/paperclip/thumbnail.rb
77c77
< success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' unless animated?}", :dest => File.expand_path(dst.path))
---
> success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' if animated?}", :dest => File.expand_path(dst.path))
110c110,111
< raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
---
> #raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
> return false
似乎回形针只是引发异常而不是返回true
或false
- 没有任何异常处理。这是它的主要失败。
或者猴子补丁:
module Paperclip
class Geometry
def self.from_file file
file_path = (file.respond_to?(:path) ? file.path : file) #.gsub(/\s/, '\\\\\1')
raise(Errors::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank?
geometry = begin
silence_stream(STDERR) do
Paperclip.run("identify", "-format %wx%h :file", :file => file_path)
end
rescue Cocaine::ExitStatusError
""
rescue Cocaine::CommandNotFoundError => e
raise Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
parse(geometry) ||
raise(Errors::NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command. (from #{file.inspect})"))
end
end
class Thumbnail
def make
src = @file
dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
dst.binmode
begin
parameters = []
parameters << source_file_options
parameters << ":source"
parameters << transformation_command
parameters << convert_options
parameters << ":dest"
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
success = convert(parameters, :source => "#{File.expand_path(src.path)}#{'[0]' if animated?}", :dest => File.expand_path(dst.path))
rescue Cocaine::ExitStatusError => e
raise Paperclip::Error, "There was an error processing the thumbnail for #{@basename}" if @whiny
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `convert` command. Please install ImageMagick.")
end
dst
end
protected
def identified_as_animated?
ANIMATED_FORMATS.include? identify("-format %m :file", :file => "#{@file.path}[0]").to_s.downcase.strip
rescue Cocaine::ExitStatusError => e
#raise Paperclip::Error, "There was an error running `identify` for #{@basename}" if @whiny
return false
rescue Cocaine::CommandNotFoundError => e
raise Paperclip::Errors::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
end
end