paperclip error while reporcessing after rails 3 upgrade
Asked Answered
C

2

4

I have paperclip working uploading and saving different styles for images but when i go to crop the image using jcrop from railscasts tutorial it doesnt crop image. I get this error

[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>

This was working in rails 2.3.9 but hvae just upgraded to rails 3.0.3 I have got all latest gems etc.

The cropper.rb file is as follows and is in the initializers dir

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

The sizes are getting into this but no actually cropping the image.

Please can anyone help with this ?

thanks alot Richard Moss

Cordi answered 18/1, 2011 at 12:38 Comment(1)
patshaughnessy.net/2010/5/23/…Cochard
G
12

Hereis my working file:

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
Guyguyana answered 18/1, 2011 at 17:57 Comment(0)
G
3

Just as an addendum to the accepted answer (assuming you're following Ryan Bates' Railscast), you'll need to remove the following lines from your model:

after_update :reprocess_avatar, :if => :cropping?

def reprocess_avatar
  avatar.reprocess!
end

This will cause an infinite loop. You then just need to move the logic to the update action in the controller by adding something like this:

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

I got hung up on this for a while, so thought I'd share.

Gigahertz answered 29/11, 2013 at 8:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.