Ruby on Rails, Paperclip: “identify” command working in cmd but not in app

自古美人都是妖i 提交于 2019-11-30 15:54:56

Updated the following in development.rb and it started working

Paperclip.options[:command_path] = 'C:/Progra~1/ImageM~1.8-q'

This was on a Windows 2008 32 Bit Server

This is due to a bug in the Paperclip gem in lib/paperclip/command_line.rb file.

def full_path(binary)
  [self.class.path, binary].compact.join("/")
end

The full_path function generates command file name with a backslash.

"C:\Program Files\ImageMagick-6.7.0-Q16"/identify

This command fails on Windows as the cmd shell throws an error when the command file is a long file name with a back slash.

There are two ways to fix the issue.

Use the short file name as the command path.

Paperclip.options[:command_path] = 'C:/PROGRA~1/IMAGEM~1.0-Q'

Note: You can get the short file name as follows:

dir /x "C:\Program Files*"
dir /x "C:\Program Files\ImageMagick-6.7.0-Q16*"

Monkey patch the Paperclip gem in config\initializers\paperclip.rb.

I tested this on 2.3.11.

class Paperclip::CommandLine
  def full_path(binary)
    [self.class.path, binary].compact.join(File::ALT_SEPARATOR||File::SEPARATOR)
  end
end

Now, the identify command is generated with the correct path seperator.

"C:\Program Files\ImageMagick-6.7.0-Q16"\identify

I prefer the second approach as command_path is easier to configure.

Open a command prompt and type echo %path% your imagemagick path should appear there.

Also try changing the :command_path to C:/Progra~1/ImageM~1

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