Skip to content

Instantly share code, notes, and snippets.

Created July 23, 2009 14:28
Show Gist options
  • Save anonymous/152990 to your computer and use it in GitHub Desktop.
Save anonymous/152990 to your computer and use it in GitHub Desktop.
class Foo < ActiveRecord::Base
has_attached_file :photo,
:styles => {
:icon => "32x32#",
:thumb => "160x130",
:area => "590x480" },
:processors => [:jcropper]
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
def crop_str
if !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
"-crop #{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}"
else
""
end
end
end
module Paperclip
class Jcropper < Thumbnail
def transformation_command
scale, crop = @current_geometry.transformation_to(@target_geometry, crop?)
trans = ''
if crop_string?
trans << " #{crop_string}"
trans << " -resize \"#{scale}\""
else
trans << " -resize \"#{scale}\""
trans << " -crop \"#{crop}\" +repage" if crop
end
trans
end
def crop_string
@attachment.instance.crop_str
end
def crop_string?
not crop_string.blank?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment