【问题标题】:paperclip error while reporcessing after rails 3 upgradeRails 3升级后重新处理时出现回形针错误
【发布时间】:2011-06-11 01:58:37
【问题描述】:

我有回形针正在上传和保存不同样式的图像,但是当我使用 railscasts 教程中的 jcrop 裁剪图像时,它不会裁剪图像。我收到此错误

[paperclip] identify -format %wx%h '/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-0[0]' 2>/dev/null
[paperclip] convert '/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-0[0]' -crop 28x32+13+15-resize "400x400>" '/var/folders/z+/z+KzOZBFE9irCpbMKKBGFk+++TI/-Tmp-/paperclip-reprocess20110118-19757-1wtrjaj-020110118-19757-1a5n558-0.jpg' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for paperclip-reprocess20110118-19757-1wtrjaj-0>

这在 rails 2.3.9 中工作,但 hvae 刚刚升级到 rails 3.0.3 我已经获得了所有最新的 gem 等。

cropper.rb 文件如下,在初始化器目录中

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(" ").sub(/ -crop \S+/, '')
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance   

      if target.cropping?
        " -crop #{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}"
      end
    end
  end
end

尺寸已进入此范围,但实际上并未裁剪图像。

请问有人可以帮忙吗?

非常感谢 理查德·莫斯

【问题讨论】:

标签: jquery ruby-on-rails ruby paperclip


【解决方案1】:

这是我的工作文件:

module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if crop_command
        crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ') # super returns     an array like this: ["-resize", "100x", "-crop", "100x100+0+0", "+repage"]
      else
        super
      end
    end

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ["-crop", "#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}"]
      end
    end
  end
end

【讨论】:

    【解决方案2】:

    作为已接受答案的附录(假设您正在关注 Ryan Bates 的 Railscast),您需要从模型中删除以下行:

    after_update :reprocess_avatar, :if => :cropping?
    
    def reprocess_avatar
      avatar.reprocess!
    end
    

    这将导致无限循环。然后,您只需通过添加如下内容将逻辑移动到控制器中的更新操作:

    if @user.cropping?
      @user.avatar.reprocess!
    end
    

    我已经挂断了一段时间,所以想分享一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多