【问题标题】:Ruby on Rails, Paperclip: "identify" command working in cmd but not in appRuby on Rails,Paperclip:“识别”命令在 cmd 中工作但在应用程序中不起作用
【发布时间】:2011-02-12 23:31:17
【问题描述】:

我已经在我的 Windows 7 64 位上安装了 ImageMagick,并且我有 Paperclip Gem。我的用户模型如下所示:

   class User < ActiveRecord::Base
  # Paperclip
  has_attached_file :photo,
    :styles => {
      :thumb=> "100x100#",
      :small  => "150x150>" }
  end

在 paperclip.rb 和 development.rb 我有:

Paperclip.options[:command_path] = 'C:/Program Files/ImageMagick-6.6.7-Q16'

我的 _form 如下所示:

    <%= form_for(@user, :html => { :multipart => true } )  do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :username %><br />
    <%= f.text_field :username %>
  </div>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </div>
  <div class="field">
    <%= f.label :crypted_password %><br />
    <%= f.text_field :crypted_password %>
  </div>
  <div class="field">
    <%= f.label :password_salt %><br />
    <%= f.text_field :password_salt %>
  </div>
 <%= f.file_field :photo%>
  <div class="actions">
    <%= f.submit %>
  </div>

<% end %>

enter code here

上传图片时出现以下错误:

[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: C:/Users/John/AppData/Local/Temp/stream20110212-6576-1us1cdl.png is not recognized by the 'identify' command.>  

我可以在我的 cmd 中对该图像使用 identify,它会毫无问题地返回有关图像的元数据。

如果可以,请提供帮助。我已经在这个问题上停留了一天多。

【问题讨论】:

    标签: ruby-on-rails-3 imagemagick paperclip


    【解决方案1】:

    这是由于 lib/paperclip/command_line.rb file 中的 Paperclip gem 中的一个错误。

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

    full_path 函数生成带有反斜杠的命令文件名。

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

    此命令在 Windows 上失败,因为当命令文件是带有反斜杠的 long file name 时,cmd shell 会引发错误。

    有两种方法可以解决此问题。

    使用short file name 作为命令路径。

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

    注意:短文件名的获取方式如下:

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

    Monkey 在config\initializers\paperclip.rb 中修补回形针宝石。

    我在 2.3.11 上测试了这个。

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

    现在,identify 命令使用正确的路径分隔符生成。

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

    我更喜欢第二种方法,因为command_path 更容易配置。

    【讨论】:

      【解决方案2】:

      在 development.rb 中更新了以下内容并开始工作

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

      这是在 Windows 2008 32 位服务器上

      【讨论】:

        【解决方案3】:

        打开命令提示符并输入 echo %path% 你的 imagemagick 路径应该会出现在那里。

        还可以尝试将:command_path 更改为C:/Progra~1/ImageM~1

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-07-17
          • 1970-01-01
          • 2017-11-09
          • 2013-05-09
          • 1970-01-01
          • 1970-01-01
          • 2012-04-17
          • 1970-01-01
          相关资源
          最近更新 更多