Created
July 23, 2009 14:28
-
-
Save anonymous/152990 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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