RailsCasts Pro episodes are now free!

Learn more or hide this

Seva Baskin's Profile

GitHub User: sevab

Site: www.twitter.com/baskind

Comments by Seva Baskin

Avatar

Adjusting coordinates for the original resolution can also be done in the backend rather than in the javascript on the front-end. Which is particularly useful if you have your JS in an external CoffeeScript file and not in the view. To do so, modify your crop_command in cropper.rb processor:

ruby
module Paperclip
  class Cropper < Thumbnail

    ...

    def crop_command
      target = @attachment.instance
      if target.cropping?
        ratio = target.photo_geometry(:original).width  / target.photo_geometry(:large).width
        ["-crop", "#{(target.crop_w.to_i*ratio).round}x#{(target.crop_h.to_i*ratio).round}+#{(target.crop_x.to_i*ratio).round}+#{(target.crop_y.to_i*ratio).round}"]
      end
    end
  end
end