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

前端 未结 3 852

I\'ve installed ImageMagick on my Windows 7 64bit and I have the Paperclip Gem. My User model looks like this:

   class User < ActiveRecord::Base
  # Pape         


        
相关标签:
3条回答
  • 2021-01-03 10:33

    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

    0 讨论(0)
  • 2021-01-03 10:33

    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

    0 讨论(0)
  • 2021-01-03 10:35

    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.

    0 讨论(0)
提交回复
热议问题