'identify'命令无法识别Paperclip :: NotIdentifiedByImageMagickError图像 [英] Paperclip::NotIdentifiedByImageMagickError image is not recognized by the 'identify' command

查看:146
本文介绍了'identify'命令无法识别Paperclip :: NotIdentifiedByImageMagickError图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编辑模型时遇到此错误,当我删除与之关联的图像时我选择了另一个:

i´m getting this error when editing a model specifically when i delete an image associated to it and I select another:

Paperclip::NotIdentifiedByImageMagickError in Admin/packsController#update

Chrysanthemumprueba4.jpg is not recognized by the 'identify' command.

C:/Users/.../vendor/plugins/thoughtbot-paperclip-fc792c8/lib/paperclip/geometry.rb:24:in `from_file'

但是当我创建一个新包并为其选择图像时,它可以正常工作。

But when i create a new pack and I select images for it, it works ok.

我有两个表:pack和pack_images,pack_images包含相关包的照片,以下是关系:

I have two tables: packs and pack_images,and pack_images has the photos for the pack associated, here are the relations:

class Pack < ActiveRecord::Base
  has_many :pack_images, :dependent => :destroy
end

class PackImage < ActiveRecord::Base
  belongs_to :pack
  attr_accessor :height, :width

  has_attached_file :photo, :url => "/:attachment/:class/:id/:style_:basename.:extension", :styles => {:principal => "240x240>", :original => "400x400>", ...}

end

这是控制器的操作会抛出错误:

This is the controller's action that throws me the error:

def update
    @pack = Pack.find(params[:id])
    @pack.pack_products

    unless params[:pack][:pack_images_attributes].nil?
      params[:pack][:pack_images_attributes].count.times do |i|
        unless params[:pack][:pack_images_attributes][:"#{i.to_s}"][:photo].blank?
          file = params[:pack][:pack_images_attributes][:"#{i.to_s}"][:photo]
          dimensions = Paperclip::Geometry.from_file(file)
          @pack.pack_images[i].width = dimensions.width              
          @pack.pack_images[i].height = dimensions.height
        end
      end
    end

  respond_to do |format|
  @pack.update_attributes(params[:pack])
  format.html { redirect_to(admin_pack_path(@pack.id), :notice => 'Pack updated') }

end

我注意到,在更新时我得到的参数少(只有照片的名字)比创建(照片的名称,文件类型,宽度,高度等)。

I noticed that, when updating I get less parameters (only the photo's name) than when creating (photo's name,file type,width,height,etc).

我希望你能帮助我

非常感谢

推荐答案

它曾经对PDF和图像工作正常,试用了一个小时左右,一切都跟着后来我用谷歌搜索了我的模型中发现的问题 has_attached_file:附件

it used to work fine for pdf and images, tried out for an hour or so, followed everything I googled later the problem was found in my model has_attached_file :attachment,

:styles => {:original=> "125x125#"} 

必须对此行发表评论,它适用于其他附件,如docx或odt等等。

had to comment this line, and it worked for other attachments like docx or odt etc..

所以在你的情况下:styles => {:principal => 240x240>,:original => 400x400>}
退房并发表评论。

so in your case :styles => {:principal => "240x240>", :original => "400x400>"} check out and comment.

这篇关于'identify'命令无法识别Paperclip :: NotIdentifiedByImageMagickError图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆