所以我使用的是 windows 7、Rails 3、最新的回形针 gem 和 ImageMagick-6.7.7-Q16(在 cmd 中测试),我的 PATH 环境已更新。
模型
class Image < ActiveRecord::Base
attr_accessible :description, :user_id, :file
has_attached_file :file, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :storage => :filesystem
belongs_to :user
#validations
validates_attachment_presence :file
validates_attachment_size :file, :less_than => 4.megabytes
validates_attachment_content_type :file, :content_type => [ 'image/gif', 'image/png', 'image/x-png', 'image/jpeg', 'image/pjpeg', 'image/jpg' ]
end
形式
<%= form_for(@image, :html => { :multipart => true }) do |image| %>
<div class="control-group">
<%= image.label :description, "Description", :class => 'control-label' %>
<div class="controls">
<div class="input-prepend">
<%= image.text_field :description %>
</div>
</div>
</div>
<div class="control-group">
<%= image.label :file, "Image", :class => 'control-label' %>
<div class="controls">
<div class="input-prepend">
<%= image.file_field :file %>
</div>
</div>
</div>
<%= image.hidden_field :user_id, :value => current_user.id %>
<div class="actions">
<%= image.submit "Upload Image", :class => 'btn btn-primary btn-medium' %>
</div>
<% end %>
我的 paperclip.rb 在初始化程序中
require "paperclip"
Paperclip.options[:command_path] = 'C:\Program Files (x86)\ImageMagick-6.7.7-Q16'
Paperclip.options[:swallow_stderr] = false
Paperclip.options[:whiny_thumbnails] = true
一切正常,无需裁剪 (:styles => { :medium => "300x300>", :thumb => "100x100>" })。但是当我想制作缩略图时,回形针会抛出这个错误
Command :: identify -format %wx%h "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw5.JPG[0]"
Command :: convert "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw5.JPG[0]" -resize "300x300>" "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw520120519-7696-1p8rcsr"
[paperclip] An error was received while processing: #<Paperclip::Error: There was an error processing the thumbnail for DSCN630520120519-7696-18l3nw5>
Command :: identify -format %wx%h "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw5.JPG[0]"
Command :: convert "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw5.JPG[0]" -resize "100x100>" "C:/Users/Zaraka/AppData/Local/Temp/DSCN630520120519-7696-18l3nw520120519-7696-tx3bmo"
[paperclip] An error was received while processing: #<Paperclip::Error: There was an error processing the thumbnail for DSCN630520120519-7696-18l3nw5>
我发现上传的图像甚至不在临时文件夹中,所以这些创建的图像只有 0 个字节。如果回形针或图像上传有问题,我完全被困在这里。任何帮助将不胜感激